Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/474.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript中异步的for循环_Javascript_For Loop_Async Await - Fatal编程技术网

Javascript中异步的for循环

Javascript中异步的for循环,javascript,for-loop,async-await,Javascript,For Loop,Async Await,这是我的代码,我想运行循环直到iWhyasync没有wait?这是否回答了您的问题?这里不需要异步,因为没有异步发生。只需执行一个在超时内自行执行的递归函数即可。@Andreas如何在等待中转换此承诺?是不是cont act=wait Promise.resolve(drawArrows(actor,timeout,drawArrow,++i))…@SajeebAhamed否。我必须在drawArrows函数中使用for循环。还有,如何删除这个递归调用,并使用wait方法执行它? async f

这是我的代码,我想运行循环直到
iWhy
async
没有
wait
?这是否回答了您的问题?这里不需要异步,因为没有异步发生。只需执行一个在超时内自行执行的递归函数即可。@Andreas如何在等待中转换此承诺?是不是
cont act=wait Promise.resolve(drawArrows(actor,timeout,drawArrow,++i))
…@SajeebAhamed否。我必须在
drawArrows
函数中使用for循环。还有,如何删除这个递归调用,并使用wait方法执行它?
async function drawArrows(actors, timeout, drawArrow, i = 0) {
    drawArrow(i, timeout, actors.length-1);
    for(const actor of actors){
        new Promise(function(resolve, reject){
            setTimeout (() => {
                resolve(drawArrows(actor,timeout,drawArrow, ++i));
            },timeout) ;
        });
    };
};