shelving
Version:
Toolkit for using data in JavaScript.
35 lines (34 loc) • 1.76 kB
TypeScript
import { type StartCallback } from "../util/start.js";
import { ThroughSequence } from "./ThroughSequence.js";
/** Sequence of values that calls a `StartCallback` when it has iterators that are iterating, and calls the corresponding `StopCallback` when all iterators have finished. */
export declare class LazySequence<T = void, R = void, N = void> extends ThroughSequence<T, R, N> implements AsyncDisposable {
private _iterators;
private _starter;
/** Get the number of iterators currently registered. */
get iterators(): number;
constructor(source: AsyncIterator<T, R, N>, start: StartCallback);
[Symbol.asyncIterator](): LazyIterator<T, R, N>;
[Symbol.asyncDispose](): Promise<void>;
/**
* An iterator started iterating.
* - Add this iterator to the register.
* - Start the starter if this is the first iterator.
*/
start(iterator: LazyIterator<T, R, N>): void;
/**
* An iterator stopped iterating.
* - Add this iterator to the register
* - Stop the starter if this is the last iterator.
*/
stop(iterator: LazyIterator<T, R, N>): void;
}
/** Internal `Iterator` that allows the lazy sequence to work. */
declare class LazyIterator<T, R, N> implements AsyncIterator<T, R | undefined, N | undefined> {
private _sequence;
constructor(sequence: LazySequence<T, R | undefined, N | undefined>);
next(value?: N | undefined): Promise<IteratorResult<T, R | undefined>>;
return(value?: R | undefined | PromiseLike<R | undefined>): Promise<IteratorResult<T, R | undefined>>;
throw(reason?: unknown): Promise<IteratorResult<T, R | undefined>>;
_result(result: Promise<IteratorResult<T, R | undefined>>): Promise<IteratorResult<T, R | undefined>>;
}
export {};