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.
30 lines (29 loc) • 1.03 kB
TypeScript
export type MuxCall<P> = (signal: AbortSignal, p: P) => void;
export type MuxTrainArg<T, P> = {
/**
* Wired to the internal group's halt handler.
* Can prevent shutdown of an unused train, just delay.
*/
halt?: (groupSignal: AbortSignal, resumeSignal: AbortSignal) => Promise<void>;
/**
* Called if an error occured trying to set up the train.
*/
error?: (error: Error) => void;
/**
* Builds the train that passengers are connecting to.
*
* It is valid/encouraged for this to throw, or the `done` return to throw.
*/
build(signal: AbortSignal): Promise<{
target: T;
done: Promise<any>;
}>;
/**
* Connects this passenger to the current train.
*
* If this throws, the whole train will crash.
* If the connection is dangerous, wrap in something that informs the {@link P}.
*/
connect(signal: AbortSignal, t: T, p: P): void;
};
export declare function buildMuxTrain<T, P>(arg: MuxTrainArg<T, P>): MuxCall<P>;