LazySequence.start()method
An iterator started iterating.
start(iterator: LazyIterator<T, R, N>): void
new LazySequence<T, R, N>(source: AsyncIterator<T, R, N>, start: StartCallback)
| Param | Type | |
|---|---|---|
source | AsyncIterator<T, R, N> | Async iterator to pull values from. required |
start | StartCallback | Callback run when the first iterator starts; its returned stop callback runs when the last iterator finishes. required |
| Return | |
|---|---|
LazySequence<T, R, N> | Sequence of values that calls a StartCallback when it has iterators that are iterating, and calls the corresponding StopCallback when all iterators have finished. |
| Property | Type | |
|---|---|---|
.iterators | number | Number of iterators currently registered as iterating. required readonly |
Sequence of values that calls a StartCallback when it has iterators that are iterating, and calls the corresponding StopCallback when all iterators have finished.
start callback runs lazily on the first active iterator and the returned stop callback runs when the last iterator finishes.A ThroughSequence paired with a start/stop callback. The StartCallback runs when the first iterator begins iterating; the StopCallback it returns runs when the last iterator finishes. This is the sequence equivalent of an observable subscription — work happens only while something is listening.
Pass a source iterator and a start callback. The callback sets up the work and returns a teardown function:
import { DeferredSequence, LazySequence } from "shelving/sequence";
const deferred = new DeferredSequence<number>();
const seq = new LazySequence(deferred, () => {
const id = setInterval(() => deferred.resolve(Date.now()), 500);
return () => clearInterval(id); // StopCallback — runs when the last iterator finishes.
});
for await (const ts of seq) {
console.log(ts); // the interval runs only for the duration of this loop
}const seq = new LazySequence(source, () => {
const timer = setInterval(tick, 1000);
return () => clearInterval(timer); // Stop callback.
});An iterator started iterating.
start(iterator: LazyIterator<T, R, N>): void
An iterator stopped iterating.
stop(iterator: LazyIterator<T, R, N>): void