The async function*
keywords can be used to define an asynchronous generator function inside an expression.
The async function*
keywords can be used to define an asynchronous generator function inside an expression.
async function* (param0) { statements } async function* (param0, param1) { statements } async function* (param0, param1, /* … ,*/ paramN) { statements } async function* name(param0) { statements } async function* name(param0, param1) { statements } async function* name(param0, param1, /* … ,*/ paramN) { statements }
name
Optional
The function name. Can be omitted, in which case the function is anonymous. The name is only local to the function body.
paramN
Optional
The name of an argument to be passed to the function. A function can have up to 255 arguments.
statements
Optional
The statements which comprise the body of the function.
An async function*
expression is very similar to and has almost the same syntax as a async function* statement. The main difference between an async function*
expression and an async function*
statement is the function name, which can be omitted in async function*
expressions to create anonymous asynchronous generator functions. See also the chapter about functions
for more information.
The following example defines an unnamed asynchronous generator function and assigns it to x
. The function yields the square of its argument:
const x = async function* (y) { yield Promise.resolve(y * y); }; x(6).next().then((res) => console.log(res.value)); // logs 36
Desktop | Mobile | Server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | Deno | Node.js | |
async_function* |
63 |
79 |
55 |
No |
50 |
12 |
63 |
63 |
55 |
46 |
12 |
8.0 |
1.0 |
10.0.0
8.10.0
|
async function*
statementAsyncGeneratorFunction
objectGeneratorFunction
objectyield
yield*
Function
object
© 2005–2022 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/async_function*