UNPKG

nope-js-browser

Version:

NoPE Runtime for the Browser. For nodejs please use nope-js-node

71 lines (70 loc) 2.28 kB
import { NopePromise } from "../promise"; import { PriorityList } from "./lists"; /** * A Task-Queue. This could be used to make parallel * Request run sequentially. For Instance during * Saving and Reading Vars to achive a consistent set * of Data. * * Usage: * * ```typescript * // Create a Queue * const _queue = new PriorityTaskQueue(); * // Create a Function * const _func = (_input: string, _cb) => { * console.log("Hallo ", _input) * _cb(null, null); * } * * const promises = [ * _queue.execute(_func, ['Welt priority=0'],0), * _queue.execute(_func, ['Welt priority=1'],1), * _queue.execute(_func, ['Welt priority=2'],2) * * ]; * * // => Hallo Welt priority=0 <- Startet directly. * // => Hallo Welt priority=2 <- Startet because it has the highest priority. * // => Hallo Welt priority=1 * ``` * @export * @class TaskQeue */ export declare class ParallelPriorityTaskQueue { protected _queue: PriorityList<{ func: (...args: any[]) => void; cancel: () => void; args: any; resolve: (data: any) => void; reject: (err: any) => void; }>; protected _runningTasks: number; protected _counter: number; maxParallel: number; usePriority: boolean; /** * Executes the given Task. If now Task is running it is executed immediatelly, * otherwise it is pushed in the queue and call if the other tasks are call. * * @param {any} _func The Function which should be called. * @param {any} _param The Data which should be used for the call. * @param {any} _callback The Callback, which should be called after * @memberof TaskQeue */ execute<T>(func: (...args: any[]) => T | Promise<T>, args: any[], priority?: number, cancel?: () => void): NopePromise<T>; protected _execute(data: { func: (...args: any[]) => any | Promise<any>; args: any[]; cancel: () => void; resolve: (data: any) => void; reject: (err: any) => void; }): void; /** * Internal Function to Finish all Tasks. * * @protected * @memberof PriorityTaskQueue */ protected _finish(): void; get length(): number; }