docs.rodeo

MDN Web Docs mirror

AsyncGeneratorFunction

The AsyncGeneratorFunction object provides methods for async generator functions. In JavaScript, every async generator function is actually an AsyncGeneratorFunction object.

Note that AsyncGeneratorFunction is not a global object. It can be obtained with the following code:

const AsyncGeneratorFunction = async function* () {}.constructor;

AsyncGeneratorFunction is a subclass of {{jsxref("Function")}} .

{{InteractiveExample("JavaScript Demo: AsyncGeneratorFunction", "taller")}} 

const AsyncGeneratorFunction = async function* () {}.constructor;

const foo = new AsyncGeneratorFunction(`
  yield await Promise.resolve('a');
  yield await Promise.resolve('b');
  yield await Promise.resolve('c');
`);

let str = "";

async function generate() {
  for await (const val of foo()) {
    str += val;
  }
  console.log(str);
}

generate();
// Expected output: "abc"

Constructor

Instance properties

Also inherits instance properties from its parent {{jsxref("Function")}} .

These properties are defined on AsyncGeneratorFunction.prototype and shared by all AsyncGeneratorFunction instances.

These properties are own properties of each AsyncGeneratorFunction instance.

Instance methods

Inherits instance methods from its parent {{jsxref("Function")}} .

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN