我将如何执行for循环,直到每个循环的功能完成?节点js btw

问题描述 投票:0回答:1

我当前的代码是这样:

const fs = require('fs');
var file = fs.readFileSync('file.txt').toString().split("\n");

for(i in file) {
    var [thing1, thing2, thing3] = file[i].split(":");
    myfunction(thing1, thing2, thing3);
}

这将使用文件中的一些信息为文件中的每一行执行一个功能。由于技术原因,我一次只能运行一次该功能。如何让for循环在再次循环之前等待函数完成?

javascript node.js for-loop
1个回答
0
投票

如果我的功能已同步,则您的代码已在工作中

其他方式:

await myfunction(thing1, thing2, thing3);

请确保在代码块之前添加async

© www.soinside.com 2019 - 2024. All rights reserved.