Skip to main content
Module

x/effection/mod.ts>each

Structured concurrency and effects for JavaScript
Latest
function each
import { each } from "https://deno.land/x/effection@3.0.3/mod.ts";

Consume an effection stream using a simple for-of loop.

Given any stream, you can access its values sequentially using the each() operation just as you would use for await of loop with an async iterable:

function* logvalues(stream) {
  for (let value of yield* each(stream)) {
    console.log(value);
    yield* each.next()
  }
}

You must always invoke each.next at the end of each iteration of the loop, including if the interation ends with a continue statement.

Note that just as with async iterators, there is no way to consume the TClose value of a stream using the for-each loop.

Parameters

stream: Stream<T, unknown>
  • the stream to iterate

Returns

Operation<Iterable<T>>

an operation to iterate stream