| 1 | declare function fastq<C, T = any, R = any>(context: C, worker: fastq.worker<C, T, R>, concurrency: number): fastq.queue<T, R>
|
|---|
| 2 | declare function fastq<C, T = any, R = any>(worker: fastq.worker<C, T, R>, concurrency: number): fastq.queue<T, R>
|
|---|
| 3 |
|
|---|
| 4 | declare namespace fastq {
|
|---|
| 5 | type worker<C, T = any, R = any> = (this: C, task: T, cb: fastq.done<R>) => void
|
|---|
| 6 | type asyncWorker<C, T = any, R = any> = (this: C, task: T) => Promise<R>
|
|---|
| 7 | type done<R = any> = (err: Error | null, result?: R) => void
|
|---|
| 8 | type errorHandler<T = any> = (err: Error, task: T) => void
|
|---|
| 9 |
|
|---|
| 10 | interface queue<T = any, R = any> {
|
|---|
| 11 | /** Add a task at the end of the queue. `done(err, result)` will be called when the task was processed. */
|
|---|
| 12 | push(task: T, done?: done<R>): void
|
|---|
| 13 | /** Add a task at the beginning of the queue. `done(err, result)` will be called when the task was processed. */
|
|---|
| 14 | unshift(task: T, done?: done<R>): void
|
|---|
| 15 | /** Pause the processing of tasks. Currently worked tasks are not stopped. */
|
|---|
| 16 | pause(): any
|
|---|
| 17 | /** Resume the processing of tasks. */
|
|---|
| 18 | resume(): any
|
|---|
| 19 | running(): number
|
|---|
| 20 | /** Returns `false` if there are tasks being processed or waiting to be processed. `true` otherwise. */
|
|---|
| 21 | idle(): boolean
|
|---|
| 22 | /** Returns the number of tasks waiting to be processed (in the queue). */
|
|---|
| 23 | length(): number
|
|---|
| 24 | /** Returns all the tasks be processed (in the queue). Returns empty array when there are no tasks */
|
|---|
| 25 | getQueue(): T[]
|
|---|
| 26 | /** Removes all tasks waiting to be processed, and reset `drain` to an empty function. */
|
|---|
| 27 | kill(): any
|
|---|
| 28 | /** Same than `kill` but the `drain` function will be called before reset to empty. */
|
|---|
| 29 | killAndDrain(): any
|
|---|
| 30 | /** Removes all tasks waiting to be processed, calls each task's callback with an abort error (rejects promises for promise-based queues), and resets `drain` to an empty function. */
|
|---|
| 31 | abort(): any
|
|---|
| 32 | /** Set a global error handler. `handler(err, task)` will be called each time a task is completed, `err` will be not null if the task has thrown an error. */
|
|---|
| 33 | error(handler: errorHandler<T>): void
|
|---|
| 34 | /** Property that returns the number of concurrent tasks that could be executed in parallel. It can be altered at runtime. */
|
|---|
| 35 | concurrency: number
|
|---|
| 36 | /** Property (Read-Only) that returns `true` when the queue is in a paused state. */
|
|---|
| 37 | readonly paused: boolean
|
|---|
| 38 | /** Function that will be called when the last item from the queue has been processed by a worker. It can be altered at runtime. */
|
|---|
| 39 | drain(): any
|
|---|
| 40 | /** Function that will be called when the last item from the queue has been assigned to a worker. It can be altered at runtime. */
|
|---|
| 41 | empty: () => void
|
|---|
| 42 | /** Function that will be called when the queue hits the concurrency limit. It can be altered at runtime. */
|
|---|
| 43 | saturated: () => void
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | interface queueAsPromised<T = any, R = any> extends queue<T, R> {
|
|---|
| 47 | /** Add a task at the end of the queue. The returned `Promise` will be fulfilled (rejected) when the task is completed successfully (unsuccessfully). */
|
|---|
| 48 | push(task: T): Promise<R>
|
|---|
| 49 | /** Add a task at the beginning of the queue. The returned `Promise` will be fulfilled (rejected) when the task is completed successfully (unsuccessfully). */
|
|---|
| 50 | unshift(task: T): Promise<R>
|
|---|
| 51 | /** Wait for the queue to be drained. The returned `Promise` will be resolved when all tasks in the queue have been processed by a worker. */
|
|---|
| 52 | drained(): Promise<void>
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | function promise<C, T = any, R = any>(context: C, worker: fastq.asyncWorker<C, T, R>, concurrency: number): fastq.queueAsPromised<T, R>
|
|---|
| 56 | function promise<C, T = any, R = any>(worker: fastq.asyncWorker<C, T, R>, concurrency: number): fastq.queueAsPromised<T, R>
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | export = fastq
|
|---|