import EventEmitter from "wolfy87-eventemitter"; /** * Example usage * ``` * const queue = new TaskQueue(); * queue.on("exec", execCommand); * function execCommand(command, promiseHolder) { * let promise; * try{ * switch(command.method){ * case "foo": foo(command.data); * } * } catch (err) { * promise = Promise.reject(error); * } * promiseHolder.promise = promise; * } * function foo(data) { * console.log(data); // { somedata: "123" } * return Promise.resolve(); * } * queue.push("foo", { somedata: "123" }); * ``` */ export interface Command { method: string; resolve: (value?: any | PromiseLike) => void; reject: (reason?: any) => void; data?: any; } export interface PromiseHolder { promise: Promise | null; } export declare class TaskQueue extends EventEmitter { _closed: Boolean; _busy: Boolean; _queue: Command[]; private name; /** * 是否显示 log */ private isDebug; constructor(name?: string, debug?: boolean); close(): void; push(method: string, data?: any): Promise; _handlePendingCommands(): void; _handleCommand(command: Command): Promise; }