Note that to understand how the async / await works, you need to know how promises work. We make an async function finishMyTask and use await to wait for the result of operations such as queryDatabase, sendEmail, logTaskInFile etc.. await operator in the Main method. The following example shows how you could await on three different promises that could be resolved concurrently. Summary: in this tutorial, you will learn how to write asynchronous code using JavaScript async/ await keywords. Here is a quick example of async/await for writing an asynchronous function: It is better than promise.then() and makes the code easier to understand and write. See my comments in your Gist, you are using the "await" keyword wrong, it must be inside an async function. Basically, the await keyword makes JavaScript pauses the function execution until the promise settles, and resumes when the result is available. Async/Await is a long anticipated JavaScript feature that makes working with asynchronous functions much more enjoyable and easier to understand. If we contrast this solution with the solutions using promises above, we find that it is roughly the same line of code.However, async/await has made it simpler in terms of syntactical complexity. Once the promise is resolved, ... await blocks JavaScript from executing the next line of code until a promise resolves. async/await makes your asynchronous code written in synchronous fashion, hence making it readable. The await keyword before a promise, makes JavaScript wait until that promise settles. – Ben March Dec 10 '15 at 20:58 Please have a look at the "Update 1" in gist. You should use async functions when you want to use the await keyword inside that function. The async and await keywords are available in C# 5 and later. Examples.
Beginning with C# 7.1, the Main method, which is the application entry point, can return Task or Task