@types/async 3.2.1 → 3.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. async/README.md +1 -1
  2. async/index.d.ts +179 -67
  3. async/package.json +3 -3
async/README.md CHANGED
@@ -8,7 +8,7 @@ This package contains type definitions for Async (https://github.com/caolan/asyn
8
8
  Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/async.
9
9
 
10
10
  ### Additional Details
11
- * Last updated: Mon, 27 Apr 2020 16:08:33 GMT
11
+ * Last updated: Mon, 30 Nov 2020 19:12:26 GMT
12
12
  * Dependencies: none
13
13
  * Global values: `async`
14
14
 
async/index.d.ts CHANGED
@@ -41,6 +41,7 @@ export interface AsyncAutoTaskFunction<R1, R extends Dictionary<any>, E = Error>
41
41
 
42
42
  export interface DataContainer<T> {
43
43
  data: T;
44
+ priority: number;
44
45
  }
45
46
 
46
47
  export interface CallbackContainer {
@@ -51,74 +52,181 @@ export interface PriorityContainer {
51
52
  priority: number;
52
53
  }
53
54
 
54
- export interface AsyncQueue<T> {
55
+ export interface QueueObject<T> {
56
+ /**
57
+ * Returns the number of items waiting to be processed.
58
+ */
55
59
  length(): number;
60
+
61
+ /**
62
+ * Indicates whether or not any items have been pushed and processed by the queue.
63
+ */
56
64
  started: boolean;
65
+
66
+ /**
67
+ * Returns the number of items currently being processed.
68
+ */
57
69
  running(): number;
70
+
71
+ /**
72
+ * Returns an array of items currently being processed.
73
+ */
74
+ workersList<TWorker extends DataContainer<T>, CallbackContainer>(): TWorker[];
75
+
76
+ /**
77
+ * Returns false if there are items waiting or being processed, or true if not.
78
+ */
58
79
  idle(): boolean;
80
+
81
+ /**
82
+ * An integer for determining how many worker functions should be run in parallel.
83
+ * This property can be changed after a queue is created to alter the concurrency on-the-fly.
84
+ */
59
85
  concurrency: number;
60
- push<R, E = Error>(task: T | T[], callback?: AsyncResultCallback<R, E>): void;
61
- unshift<E = Error>(task: T | T[], callback?: ErrorCallback<E>): void;
86
+
87
+ /**
88
+ * An integer that specifies how many items are passed to the worker function at a time.
89
+ * Only applies if this is a cargo object
90
+ */
91
+ payload: number;
92
+
93
+ /**
94
+ * Add a new task to the queue. Calls `callback` once the worker has finished
95
+ * processing the task.
96
+ *
97
+ * Instead of a single task, a tasks array can be submitted.
98
+ * The respective callback is used for every task in the list.
99
+ */
100
+ push<R>(task: T | T[]): Promise<R>;
101
+ push<R, E = Error>(task: T | T[], callback: AsyncResultCallback<R, E>): void;
102
+
103
+ /**
104
+ * Add a new task to the front of the queue
105
+ */
106
+ unshift<R>(task: T | T[]): Promise<R>;
107
+ unshift<R, E = Error>(task: T | T[], callback: AsyncResultCallback<R, E>): void;
108
+
109
+ /**
110
+ * The same as `q.push`, except this returns a promise that rejects if an error occurs.
111
+ * The `callback` arg is ignored
112
+ */
113
+ pushAsync<R>(task: T | T[]): Promise<R>;
114
+
115
+ /**
116
+ * The same as `q.unshift`, except this returns a promise that rejects if an error occurs.
117
+ * The `callback` arg is ignored
118
+ */
119
+ unshiftAsync<R>(task: T | T[]): Promise<R>;
120
+
121
+ /**
122
+ * Remove items from the queue that match a test function.
123
+ * The test function will be passed an object with a `data` property,
124
+ * and a `priority` property, if this is a `priorityQueue` object.
125
+ */
62
126
  remove(filter: (node: DataContainer<T>) => boolean): void;
63
127
 
128
+ /**
129
+ * A function that sets a callback that is called when the number of
130
+ * running workers hits the `concurrency` limit, and further tasks will be
131
+ * queued.
132
+ *
133
+ * If the callback is omitted, `q.saturated()` returns a promise
134
+ * for the next occurrence.
135
+ */
64
136
  saturated(): Promise<void>;
65
137
  saturated(handler: () => void): void;
138
+
139
+ /**
140
+ * A function that sets a callback that is called when the number
141
+ * of running workers is less than the `concurrency` & `buffer` limits,
142
+ * and further tasks will not be queued
143
+ *
144
+ * If the callback is omitted, `q.unsaturated()` returns a promise
145
+ * for the next occurrence.
146
+ */
147
+ unsaturated(): Promise<void>;
148
+ unsaturated(handler: () => void): void;
149
+
150
+ /**
151
+ * A minimum threshold buffer in order to say that the `queue` is `unsaturated`.
152
+ */
153
+ buffer: number;
154
+
155
+ /**
156
+ * A function that sets a callback that is called when the last item from the `queue`
157
+ * is given to a `worker`.
158
+ *
159
+ * If the callback is omitted, `q.empty()` returns a promise for the next occurrence.
160
+ */
66
161
  empty(): Promise<void>;
67
162
  empty(handler: () => void): void;
163
+
164
+ /**
165
+ * A function that sets a callback that is called when the last item from
166
+ * the `queue` has returned from the `worker`.
167
+ *
168
+ * If the callback is omitted, `q.drain()` returns a promise for the next occurrence.
169
+ */
68
170
  drain(): Promise<void>;
69
171
  drain(handler: () => void): void;
70
172
 
71
- paused: boolean;
72
- pause(): void;
73
- resume(): void;
74
- kill(): void;
75
- workersList<TWorker extends DataContainer<T>, CallbackContainer>(): TWorker[];
76
-
77
- error(): Promise<void>;
173
+ /**
174
+ * A function that sets a callback that is called when a task errors.
175
+ *
176
+ * If the callback is omitted, `q.error()` returns a promise that rejects on the next error.
177
+ */
178
+ error(): Promise<never>;
78
179
  error(handler: (error: Error, task: T) => void): void;
79
180
 
80
- unsaturated(): void;
81
- buffer: number;
82
- }
83
-
84
- export interface AsyncPriorityQueue<T> {
85
- length(): number;
86
- concurrency: number;
87
- started: boolean;
181
+ /**
182
+ * A boolean for determining whether the queue is in a paused state.
183
+ */
88
184
  paused: boolean;
89
- push<R, E = Error>(task: T | T[], priority: number, callback?: AsyncResultArrayCallback<R, E>): void;
90
- saturated: () => any;
91
- empty: () => any;
92
- drain: () => any;
93
- running(): number;
94
- idle(): boolean;
95
- pause(): void;
96
- resume(): void;
97
- kill(): void;
98
- workersList<TWorker extends DataContainer<T>, CallbackContainer, PriorityContainer>(): TWorker[];
99
- error(error: Error, data: any): void;
100
- unsaturated(): void;
101
- buffer: number;
102
- }
103
185
 
104
- export interface AsyncCargo {
105
- length(): number;
106
- payload?: number;
107
- push(task: any, callback?: Function): void;
108
- saturated(): void;
109
- empty(): void;
110
186
  /**
111
- * a function that sets a callback that is called when the last item from the queue has returned from the worker.
112
- * If the callback is omitted, q.drain() returns a promise for the next occurrence.
187
+ * A function that pauses the processing of tasks until `q.resume()` is called.
113
188
  */
114
- drain(): Promise<void>;
115
- drain(handler: () => void): void;
116
- idle(): boolean;
117
189
  pause(): void;
190
+
191
+ /**
192
+ * A function that resumes the processing of queued tasks when the queue
193
+ * is paused.
194
+ */
118
195
  resume(): void;
196
+
197
+ /**
198
+ * A function that removes the drain callback and empties remaining tasks
199
+ * from the queue forcing it to go idle. No more tasks should be pushed to
200
+ * the queue after calling this function.
201
+ */
119
202
  kill(): void;
120
203
  }
121
204
 
205
+ /**
206
+ * A priorityQueue object to manage the tasks.
207
+ *
208
+ * There are two differences between queue and priorityQueue objects:
209
+ * - `push(task, priority, [callback])` — priority should be a number. If an array of tasks is given, all tasks will be assigned the same priority.
210
+ * - The `unshift` method was removed.
211
+ */
212
+ // FIXME: can not use Omit due to ts version restriction. Replace Pick with Omit, when ts 3.5+ will be allowed
213
+ export interface AsyncPriorityQueue<T> extends Pick<QueueObject<T>, Exclude<keyof QueueObject<T>, 'push' | 'unshift'>> {
214
+ push<R>(task: T | T[], priority?: number): Promise<R>;
215
+ push<R, E = Error>(task: T | T[], priority: number, callback: AsyncResultCallback<R, E>): void;
216
+ }
217
+
218
+ /**
219
+ * @deprecated this is a type that left here for backward compatibility.
220
+ * Please use QueueObject instead
221
+ */
222
+ export type AsyncQueue<T> = QueueObject<T>;
223
+
224
+ /**
225
+ * @deprecated this is a type that left here for backward compatibility.
226
+ * Please use QueueObject instead
227
+ */
228
+ export type AsyncCargoQueue<T = any> = QueueObject<T>;
229
+
122
230
  // Collections
123
231
  export function each<T, E = Error>(arr: IterableCollection<T>, iterator: AsyncIterator<T, E>, callback: ErrorCallback<E>): void;
124
232
  export function each<T, E = Error>(arr: IterableCollection<T>, iterator: AsyncIterator<T, E>): Promise<void>;
@@ -149,9 +257,9 @@ export function mapValuesLimit<T, R, E = Error>(
149
257
  callback: AsyncResultObjectCallback<R, E>
150
258
  ): void;
151
259
  export function mapValuesLimit<T, R, E = Error>(
152
- obj: Dictionary<T>,
153
- limit: number,
154
- iteratee: (value: T, key: string, callback: AsyncResultCallback<R, E>) => void
260
+ obj: Dictionary<T>,
261
+ limit: number,
262
+ iteratee: (value: T, key: string, callback: AsyncResultCallback<R, E>) => void
155
263
  ): Promise<R>;
156
264
 
157
265
  export function mapValues<T, R, E = Error>(obj: Dictionary<T>, iteratee: (value: T, key: string, callback: AsyncResultCallback<R, E>) => void, callback: AsyncResultObjectCallback<R, E>): void;
@@ -207,8 +315,8 @@ export function parallel<T, R, E = Error>(tasks: Array<AsyncFunction<T, E>> | Di
207
315
  export function parallelLimit<T, E = Error>(tasks: Array<AsyncFunction<T, E>>, limit: number, callback?: AsyncResultArrayCallback<T, E>): void;
208
316
  export function parallelLimit<T, E = Error>(tasks: Dictionary<AsyncFunction<T, E>>, limit: number, callback?: AsyncResultObjectCallback<T, E>): void;
209
317
  export function parallelLimit<T, R, E = Error>(tasks: Array<AsyncFunction<T, E>> | Dictionary<AsyncFunction<T, E>>, limit: number): Promise<R>;
210
- export function whilst<E = Error>(test: () => boolean, fn: AsyncVoidFunction<E>, callback: ErrorCallback<E>): void;
211
- export function whilst<R, E = Error>(test: () => boolean, fn: AsyncVoidFunction<E>): Promise<R>;
318
+ export function whilst<E = Error>(test: (cb: (err: any, truth: boolean) => boolean) => boolean, fn: AsyncVoidFunction<E>, callback: ErrorCallback<E>): void;
319
+ export function whilst<R, E = Error>(test: (cb: (err: any, truth: boolean) => boolean) => boolean, fn: AsyncVoidFunction<E>): Promise<R>;
212
320
  export function doWhilst<T, E = Error>(fn: AsyncFunctionEx<T, E>, test: (...results: T[]) => boolean, callback: ErrorCallback<E>): void;
213
321
  export function doWhilst<T, R, E = Error>(fn: AsyncFunctionEx<T, E>, test: (...results: T[]) => boolean): Promise<R>;
214
322
  export function until<E = Error>(test: () => boolean, fn: AsyncVoidFunction<E>, callback: ErrorCallback<E>): void;
@@ -223,37 +331,41 @@ export function compose(...fns: Function[]): Function;
223
331
  export function seq(...fns: Function[]): Function;
224
332
  export function applyEach(fns: Function[], ...argsAndCallback: any[]): void; // applyEach(fns, args..., callback). TS does not support ... for a middle argument. Callback is optional.
225
333
  export function applyEachSeries(fns: Function[], ...argsAndCallback: any[]): void; // applyEachSeries(fns, args..., callback). TS does not support ... for a middle argument. Callback is optional.
226
- export function queue<T, E = Error>(worker: AsyncWorker<T, E>, concurrency?: number): AsyncQueue<T>;
227
- export function queue<T, R, E = Error>(worker: AsyncResultIterator<T, R, E>, concurrency?: number): AsyncQueue<T>;
228
- export function priorityQueue<T, E = Error>(worker: AsyncWorker<T, E>, concurrency: number): AsyncPriorityQueue<T>;
229
- export function cargo<E = Error>(worker: (tasks: any[], callback: ErrorCallback<E>) => void, payload?: number): AsyncCargo;
334
+ export function queue<T, E = Error>(worker: AsyncWorker<T, E>, concurrency?: number): QueueObject<T>;
335
+ export function queue<T, R, E = Error>(worker: AsyncResultIterator<T, R, E>, concurrency?: number): QueueObject<T>;
336
+ export function priorityQueue<T, E = Error>(worker: AsyncWorker<T, E>, concurrency?: number): AsyncPriorityQueue<T>;
337
+ export function cargo<T, E = Error>(worker: AsyncWorker<T[], E>, payload?: number): QueueObject<T>;
338
+ export function cargoQueue<T, E = Error>(
339
+ worker: AsyncWorker<T[], E>,
340
+ concurrency?: number,
341
+ payload?: number,
342
+ ): QueueObject<T>;
230
343
  export function auto<R extends Dictionary<any>, E = Error>(tasks: AsyncAutoTasks<R, E>, concurrency?: number, callback?: AsyncResultCallback<R, E>): void;
231
344
  export function auto<R extends Dictionary<any>, E = Error>(tasks: AsyncAutoTasks<R, E>, callback?: AsyncResultCallback<R, E>): void;
232
345
  export function autoInject<E = Error>(tasks: any, callback?: AsyncResultCallback<any, E>): void;
233
346
 
347
+ export interface RetryOptions {
348
+ times?: number;
349
+ interval?: number | ((retryCount: number) => number);
350
+ errorFilter?: (error: Error) => boolean;
351
+ }
234
352
  export function retry<T, E = Error>(
235
- opts?:
236
- | number
237
- | {
238
- times?: number;
239
- interval?: number | ((retryCount: number) => number);
240
- errorFilter?: (error: Error) => boolean;
241
- },
353
+ opts?: number | RetryOptions,
242
354
  task?: (callback: AsyncResultCallback<T, E>, results: any) => void,
243
355
  ): Promise<void>;
244
356
  export function retry<T, E = Error>(
245
- opts?:
246
- | number
247
- | {
248
- times?: number;
249
- interval?: number | ((retryCount: number) => number);
250
- errorFilter?: (error: Error) => boolean;
251
- },
357
+ opts?: number | RetryOptions,
252
358
  task?: (callback: AsyncResultCallback<T, E>, results: any) => void,
253
359
  callback?: AsyncResultCallback<any, E>,
254
360
  ): void;
255
361
 
256
- export function retryable<T, E = Error>(opts: number | {times: number, interval: number}, task: AsyncFunction<T, E>): AsyncFunction<T, E>;
362
+ export function retryable<T, E = Error>(task: AsyncFunction<T, E>): AsyncFunction<T, E>;
363
+ export function retryable<T, E = Error>(
364
+ opts:
365
+ | number
366
+ | RetryOptions & {arity?: number},
367
+ task: AsyncFunction<T, E>
368
+ ): AsyncFunction<T, E>;
257
369
  export function apply<E = Error>(fn: Function, ...args: any[]): AsyncFunction<any, E>;
258
370
  export function nextTick(callback: Function, ...args: any[]): void;
259
371
  export const setImmediate: typeof nextTick;
async/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@types/async",
3
- "version": "3.2.1",
3
+ "version": "3.2.5",
4
4
  "description": "TypeScript definitions for Async",
5
5
  "license": "MIT",
6
6
  "contributors": [
@@ -59,6 +59,6 @@
59
59
  },
60
60
  "scripts": {},
61
61
  "dependencies": {},
62
- "typesPublisherContentHash": "58ccc56b70520fa2b8b746c864a55a12aa2f4247c1f388d6f1b27400edba83cc",
63
- "typeScriptVersion": "2.8"
62
+ "typesPublisherContentHash": "5d3403505c739b80abfffa8203dc15c69212c682e9995f3b0e840012bd4e0ebe",
63
+ "typeScriptVersion": "3.3"
64
64
  }