Relative Content

Tag Archive for javascriptnode.jsasync-await

Don’t understand async await execution order

async function funcTwo() { return new Promise((r) => r()); } async function funcOne() { console.log(“A”); (async () => { await funcTwo(); console.log(“B”); })(); console.log(“C”); } await funcOne(); console.log(“Done”); According to my knowledge the output should be as follows: A C B Done My reasoning is: 1.funcOne runs 2.A is printed 3.async function runs and promise […]

Don’t understand async await execution order

async function funcTwo() { return new Promise((r) => r()); } async function funcOne() { console.log(“A”); (async () => { await funcTwo(); console.log(“B”); })(); console.log(“C”); } await funcOne(); console.log(“Done”); According to my knowledge the output should be as follows: A C B Done My reasoning is: 1.funcOne runs 2.A is printed 3.async function runs and promise […]

async function inside forEach

A newbie question – There is an async function inside a for loop and I want to keep collecting data and once done I want to use this information to do something. How do I perform this using a callback? I was able to achieve the same using async.whilist but I want to avoid it and understand basic callback better.