MCPcopy Create free account
hub / github.com/denoland/std / iterate

Method iterate

async/mux_async_iterator.ts:118–138  ·  view source on GitHub ↗

* Returns an async iterator of the stream. * @returns the async iterator for all the added async iterables. * * @example Usage * ```ts * import { MuxAsyncIterator } from "@std/async/mux-async-iterator"; * import { assertEquals } from "@std/assert"; * * async function* gen123(

()

Source from the content-addressed store, hash-verified

116 * ```
117 */
118 async *iterate(): AsyncIterableIterator<T> {
119 while (this.#iteratorCount > 0) {
120 // Sleep until any of the wrapped iterators yields.
121 await this.#signal.promise;
122
123 // Note that while we're looping over `yields`, new items may be added.
124 for (const { iterator, value } of this.#yields) {
125 yield value;
126 this.#callIteratorNext(iterator);
127 }
128
129 if (this.#throws.length) {
130 for (const e of this.#throws) {
131 throw e;
132 }
133 }
134 // Clear the `yields` list and reset the `signal` promise.
135 this.#yields.length = 0;
136 this.#signal = Promise.withResolvers<void>();
137 }
138 }
139
140 /**
141 * Implements an async iterator for the stream.

Callers 1

Calls 1

#callIteratorNextMethod · 0.95

Tested by

no test coverage detected