Skip to content

createExternalAsyncGenerator

The createExternalAsyncGenerator() function creates an externally controlled async generator that can emit one value or stop explicitly.

Interactive example

Syntax

typescript
function createExternalAsyncGenerator<
	GenericValue extends unknown
>(): {
	asyncGenerator: AsyncGenerator<GenericValue, void, unknown>;
	next: (value: GenericValue) => void;
	exit: () => void;
}

Parameters

This function does not take any parameter.

Return value

An object containing:

  • asyncGenerator: The async generator waiting for an external value.
  • next(value): Pushes a value to the generator.
  • exit(): Stops the generator without yielding a value.

See also

  • execute - Consumes a generator
  • asyncMap - Applies async transformations on iterables

Released under the MIT license.