ready-callback
Version:
Launch server after all async task ready
42 lines (41 loc) • 1.15 kB
TypeScript
/// <reference types="node" />
import EventEmitter from 'node:events';
import { type ReadyFunctionArg } from 'get-ready';
interface ReadyOption {
timeout?: number;
isWeakDep?: boolean;
lazyStart?: boolean;
}
interface ReadyCallbackOption {
name?: string;
timeout?: number;
isWeakDep?: boolean;
}
interface ReadyCallbackFn {
(err?: any): void;
id: string;
}
type ReadyCallbackCache = Map<string, ReadyCallbackFn>;
/**
* @class Ready
*/
declare class Ready extends EventEmitter {
isError: boolean;
cache: ReadyCallbackCache;
opt: ReadyOption;
obj: any;
ready: (flagOrFunction?: ReadyFunctionArg) => void;
constructor(opt?: ReadyOption);
start(): void;
/**
* Mix `ready` and `readyCallback` to `obj`
* @function Ready#mixin
* @param {Object} obj - The mixed object
* @return {Ready} this
*/
mixin(obj?: any): this | null;
readyCallback(name: string, opt?: ReadyCallbackOption): ReadyCallbackFn;
readyDone(id: string, opt: ReadyCallbackOption, err?: Error): boolean | this;
}
export { Ready };
export default function (opt?: ReadyOption): Ready;