租房小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
3.4 KiB

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