[removed] Asynchronous method in while loop

后端 未结 8 2071
一生所求
一生所求 2020-12-15 08:28

I\'m tackling a project that requires me to use JavaScript with an API method call. I\'m a Java programmer who has never done web development before so I\'m having some trou

8条回答
  •  孤城傲影
    2020-12-15 09:00

    Also you may try recursion solution.

    function asyncCall(cb) {
    // Some async operation
    }
    
    function responseHandler(result) {
        if (result.error()) {
            console.error(result.error());
        } else if(result.data() && result.data().length) {
            asyncCall(responseHandler);
        }
    }
    
    asyncCall(responseHandler);
    

提交回复
热议问题