Skip to content

execute ​

The execute() function fully consumes a generator by iterating over all its elements without returning a value. Used to end a chain of transformations on a generator.

Interactive example ​

Syntax ​

Synchronous signature ​

typescript
function execute<
	GenericIterator extends Iterable<unknown>
>(
	iterator: GenericIterator
): void

Asynchronous signature ​

typescript
function execute<
	GenericIterator extends AsyncIterable<unknown>
>(
	iterator: GenericIterator
): Promise<void>

Parameters ​

  • iterator: The generator (synchronous or asynchronous) to execute fully.

Return value ​

void for synchronous generators, Promise<void> for asynchronous generators.

See also ​

  • loop - Creates a generator with a custom loop
  • map - Transforms the elements of a generator

Sources ​

Released under the MIT license.