index.d.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // Type definitions for Queue 4.5.1
  2. // Project: https://github.com/jessetane/queue
  3. // Definitions by: Alex Miller <https://github.com/codex->
  4. import { EventEmitter } from "events";
  5. export interface Options {
  6. /**
  7. * Max number of jobs the queue should process concurrently.
  8. *
  9. * @default Infinity
  10. */
  11. concurrency?: number;
  12. /**
  13. * Milliseconds to wait for a job to execute its callback.
  14. *
  15. * @default 0
  16. */
  17. timeout?: number;
  18. /**
  19. * Ensures the queue is always running if jobs are available. Useful in situations where you are using a queue only for concurrency control.
  20. *
  21. * @default false
  22. */
  23. autostart?: boolean;
  24. /**
  25. * An array to set job callback arguments on.
  26. *
  27. * @default null
  28. */
  29. results?: any[];
  30. }
  31. interface Queue extends EventEmitter {
  32. /**
  33. * Max number of jobs the queue should process concurrently.
  34. */
  35. concurrency: number;
  36. /**
  37. * Milliseconds to wait for a job to execute its callback.
  38. */
  39. timeout: number;
  40. /**
  41. * Ensures the queue is always running if jobs are available.
  42. */
  43. autostart: boolean;
  44. /**
  45. * An array to set job callback arguments on.
  46. */
  47. results: any[] | null;
  48. /**
  49. * Jobs pending + jobs to process.
  50. */
  51. readonly length: number;
  52. /**
  53. * Adds one or more elements to the end of the Queue and returns the new length of the Queue.
  54. *
  55. * @param workers New workers of the Queue.
  56. */
  57. push(...workers: QueueWorker[]): number;
  58. /**
  59. * Adds one or more elements to the front of the Queue and returns the new length of the Queue.
  60. *
  61. * @param workers Workers to insert at the start of the Queue.
  62. */
  63. unshift(...workers: QueueWorker[]): number;
  64. /**
  65. * Adds and/or removes elements from the queue.
  66. *
  67. * @param start The zero-based location in the Queue from which to start removing elements.
  68. * @param deleteCount The number of elements to remove.
  69. */
  70. splice(start: number, deleteCount?: number): Queue;
  71. /**
  72. * Adds and/or removes elements from the queue.
  73. *
  74. * @param start The zero-based location in the Queue from which to start removing elements.
  75. * @param deleteCount The number of elements to remove.
  76. * @param workers Workers to insert into the Queue in place of the deleted elements.
  77. */
  78. splice(start: number, deleteCount: number, ...workers: QueueWorker[]): Queue;
  79. /**
  80. * Removes the last element from the Queue and returns that element.
  81. */
  82. pop(): QueueWorker | undefined;
  83. /**
  84. * Removes the first element from the Queue and returns that element.
  85. */
  86. shift(): QueueWorker | undefined;
  87. /**
  88. * Extracts a section of the Queue and returns Queue.
  89. *
  90. * @param start The beginning of the specified portion of the Queue.
  91. * @param end The end of the specified portion of the Queue.
  92. */
  93. slice(start?: number, end?: number): Queue;
  94. /**
  95. * Reverses the order of the elements of the Queue in place.
  96. */
  97. reverse(): Queue;
  98. /**
  99. * Returns the first (least) index of an element within the Queue equal to the specified value, or -1 if none is found.
  100. *
  101. * @param searchElement The value to locate in the Queue.
  102. * @param fromIndex The Queue index at which to begin the search. If omitted, the search starts at index 0.
  103. */
  104. indexOf(searchElement: QueueWorker, fromIndex?: number): number;
  105. /**
  106. * Returns the last (greatest) index of an element within the Queue equal to the specified value, or -1 if none is found.
  107. *
  108. * @param searchElement The value to locate in the Queue.
  109. * @param fromIndex The Queue index at which to begin the search. If omitted, the search starts at the last index in the Queue.
  110. */
  111. lastIndexOf(searchElement: QueueWorker, fromIndex?: number): number;
  112. /**
  113. * Starts the queue.
  114. *
  115. * @param callback Callback to be called when the queue empties or when an error occurs.
  116. */
  117. start(callback?: (error?: Error) => void): void;
  118. /**
  119. * Stops the queue.
  120. */
  121. stop(): void;
  122. /**
  123. * Stop and empty the queue immediately.
  124. *
  125. * @param error error of why the stop has occurred, to be passed to start callback if supplied.
  126. */
  127. end(error?: Error): void;
  128. }
  129. interface QueueConstructor {
  130. (options?: Options): Queue;
  131. new (options?: Options): Queue;
  132. }
  133. declare const Queue: QueueConstructor;
  134. export default Queue;
  135. export interface QueueWorker {
  136. (callback?: QueueWorkerCallback): void;
  137. /**
  138. * Override queue timeout.
  139. */
  140. timeout?: number;
  141. }
  142. export interface QueueWorkerCallback {
  143. (error?: Error, data?: Object): void;
  144. }