3 Answers
New AnswerI want to wait for a loop to complete... Currently I'm doing it with callback.... Is there anything to do the same thing more elegantly...?
2/17/2019 1:21:06 PM
Mohammad Tahsin3 Answers
New AnswerYou can consider use promise with async and await For example function processForLoop() { return new Promise(resolve => { for(var i=0;i<100;i++) { console.log(i) } resolve(i) }); } async function getForLoopOutput() { var out = await processForLoop(); console.log("Resolve output = " + out); // get result from output of processForLoop() } getForLoopOutput(); https://code.sololearn.com/W5VANf0x5Dj9/?ref=app
Thank you bro.... But this is hand made... Is there any dedicated logic to get the same thing?
What do you mean by hand make? The function works on any delay callback as well since async is always ready to wait for the output from Promise.
SoloLearn Inc.
4 Embarcadero Center, Suite 1455Send us a message