Async/await

It is semantically related to the concept of a coroutine and is often implemented using similar techniques, and is primarily intended to provide opportunities for the program to execute other code while waiting for a long-running, asynchronous task to complete, usually represented by promises or similar data structures.

The feature is found in C#,[1]: 10  C++, Python, F#, Hack, Julia, Dart, Kotlin, Rust,[2] Nim,[3] JavaScript, and Swift.

[7][1]: 10 Haskell lead developer Simon Marlow created the async package in 2012.

Rust added support for async/await with version 1.39.0 in 2019 using the async keyword and the .await postfix operator, both introduced in the 2018 edition of the language.

Many promise types also have additional features beyond what the async/await pattern normally uses, such as being able to set up more than one result callback or inspect the progress of an especially long-running task.

For instance, the C# compiler would likely translate the above code to something like the following before translating it to its IL bytecode format: Because of this, if an interface method needs to return a promise object, but itself does not require await in the body to wait on any asynchronous tasks, it does not need the async modifier either and can instead return a promise object directly.

Python 3.5 (2015)[19] has added support for async/await as described in PEP 492 (written and implemented by Yury Selivanov).

[20] The await operator in JavaScript can only be used from inside an async function or at the top level of a module.

[22] Here's an example (modified from this[23] article): Node.js version 8 includes a utility that enables using the standard library callback-based methods as promises.

[35] As a result, async/await makes it easier for most programmers to reason about their programs, and await tends to promote better, more robust non-blocking code in applications that require it.

[dubious – discuss] Critics of async/await note that the pattern tends to cause surrounding code to be asynchronous too; and that its contagious nature splits languages' library ecosystems between synchronous and asynchronous libraries and APIs, an issue often referred to as "function coloring".

Examples of colorless designs include Go's goroutines and Java's virtual threads.