thorish
Version:
This is a library of useful JS concepts and data structures for Node and the browser. It it, unashamedly, a dumping ground for code needed by [@samthor](https://twitter.com/samthor)'s projects.
22 lines (21 loc) • 741 B
TypeScript
export type SequenceListener<T> = (value: T, next: (args?: {
signal?: AbortSignal;
}) => Promise<T>) => any;
/**
* Sequencer is a reduced form of an event listener, which allows listeners to be run
* when a `notify()` call is made, but which provides a way for those listeners to internally get
* future events.
*
* It does not support `removeListener`, rather, pass a {@link AbortSignal}.
*/
export type Sequencer<T> = {
addListener: (fn: SequenceListener<T>, args?: {
signal?: AbortSignal;
once?: boolean;
}) => void;
notify(value: T): void;
};
/**
* Builds a sequencer. This can be spread onto another object as it does not use `this`.
*/
export declare function buildSequencer<T>(): Sequencer<T>;