Node.js - 如何让函数在继续之前等待完成

时间:2017-06-29 22:05:05

标签: javascript node.js

我有一个看起来像这样的函数:

const XML = '.xml code';

var array = [];
var i = 0; //counter

XMLExtract(XML, 'loc', false, (error, element) => {
    if (error) {
        throw new Error(error);
    }

    array[i] = element; 

    console.log(array[i]);

    function_name(array[i]); //imported function from external .js

    i++;

});

基本上我想运行 function()来返回它给出的响应,然后使用new参数再次运行 function()。但是,上面的代码不起作用,只是重叠。

我还检查过以前的解决方案:https://stackoverflow.com/a/5010339但我想我真的不知道如何实现它。有什么建议吗?

更新: external.js

module.exports = function() {

this.function_name = function() {

(async function() {

 ...

await instance.exit();

}());
};
};

0 个答案:

没有答案
相关问题