index.d.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. declare namespace fastq {
  4. type worker<C, T = any, R = any> = (this: C, task: T, cb: fastq.done<R>) => void
  5. type asyncWorker<C, T = any, R = any> = (this: C, task: T) => Promise<R>
  6. type done<R = any> = (err: Error | null, result?: R) => void
  7. type errorHandler<T = any> = (err: Error, task: T) => void
  8. interface queue<T = any, R = any> {
  9. push(task: T, done?: done<R>): void
  10. unshift(task: T, done?: done<R>): void
  11. pause(): any
  12. resume(): any
  13. idle(): boolean
  14. length(): number
  15. getQueue(): T[]
  16. kill(): any
  17. killAndDrain(): any
  18. error(handler: errorHandler): void
  19. concurrency: number
  20. drain(): any
  21. empty: () => void
  22. saturated: () => void
  23. }
  24. interface queueAsPromised<T = any, R = any> extends queue<T, R> {
  25. push(task: T): Promise<R>
  26. unshift(task: T): Promise<R>
  27. drained(): Promise<void>
  28. }
  29. function promise<C, T = any, R = any>(context: C, worker: fastq.asyncWorker<C, T, R>, concurrency: number): fastq.queueAsPromised<T, R>
  30. function promise<C, T = any, R = any>(worker: fastq.asyncWorker<C, T, R>, concurrency: number): fastq.queueAsPromised<T, R>
  31. }
  32. export = fastq