JavaScript async function* Statement
An async generator function combines async and function*: it can await promises and yield values over time, and is consumed with for await...of.
Description
The async function* declaration defines an async generator. It can use both await and yield, and returns an async iterator whose next() method returns promises. It suits data that arrives over time, such as pages of results from an API or chunks from a stream, and is usually consumed with for await...of.
Inside an async generator, await waits for a promise as usual, and yield hands a value to whoever is iterating. Each call to the iterator's next() returns a promise for { value, done }, so consumers naturally wait for each value to be ready. Requests to next() made before the previous one finishes are queued, so values always arrive in order.
They're ideal for wrapping APIs that deliver data in pieces: paginated endpoints, streamed responses, WebSocket messages or file reading. The consumer can stop early with break, which runs any finally block in the generator so it can release its resources.
Syntax
async function* name(params) {
yield await value;
}Example
Browser Support
The following information will show you the current browser support for the async function* statement. Hover over a browser icon to see the version that first introduced support for this statement.
Desktop





Tablets & Mobile





