shelving
Version:
Toolkit for using data in JavaScript.
25 lines (24 loc) • 1.25 kB
TypeScript
import { type Arguments } from "./function.js";
/** Callback function that starts something with multiple values and returns an optional stop callback. */
export type StartCallback<T extends Arguments = []> = (...values: T) => StopCallback | void;
/** Callback function that stops something. */
export type StopCallback = () => void;
/** Callback function that does nothing and returns a blackhole stop callback. */
export declare const STOPHOLE: (...args: Arguments) => StopCallback;
/**
* Wrapper class to handle state on start/stop callback process.
* - If process has already started, `starter.start()` won't be called twice (including if `start()` didn't return a `stop()` callback).
*/
export declare class Starter<T extends Arguments = []> implements Disposable {
private readonly _start;
private _started;
private _stop;
constructor(start: StartCallback<T>);
start(...values: T): void;
stop(): void;
[Symbol.dispose](): void;
}
/** Something that can be made into a `Starter` */
export type PossibleStarter<T extends Arguments> = StartCallback<T> | Starter<T>;
/** Get a `Starter` from a `PossibleStarter` */
export declare function getStarter<T extends Arguments>(start: StartCallback<T> | Starter<T>): Starter<T>;