Tutorial by Topics: await



In C#, a method declared async won't block within a synchronous process, in case of you're using I/O based operations (e.g. web access, working with files, ...). The result of such async marked methods may be awaited via the use of the awaitkeyword.

async and await build on top of promises and generators to express asynchronous actions inline. This makes asynchronous or callback code much easier to maintain.

Functions with the async keyword return a Promise, and can be called with that syntax.

Inside an async function the await keyword can be applied to any Promise, and will cause all of the function body after the await to be executed after the promise resolves.

Async/await is a set of keywords that allows writing of asynchronous code in a procedural manner without having to rely on callbacks (callback hell) or promise-chaining (.then().then().then()).

This works by using the await keyword to suspend the state of an async function, until the resolution of a promise, and using the async keyword to declare such async functions, which return a promise.

Async/await is available from node.js 8 by default or 7 using the flag --harmony-async-await.


Page 1 of 1