| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const { SyncHook, AsyncSeriesHook } = require("tapable"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-04 01:29:21 +08:00
										 |  |  | const QUEUED_STATE = 0; | 
					
						
							|  |  |  | const PROCESSING_STATE = 1; | 
					
						
							|  |  |  | const DONE_STATE = 2; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-12 19:21:47 +08:00
										 |  |  | let inHandleResult = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @template T | 
					
						
							| 
									
										
										
										
											2020-04-23 16:48:36 +08:00
										 |  |  |  * @callback Callback | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  |  * @param {Error=} err | 
					
						
							|  |  |  |  * @param {T=} result | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-04 01:29:21 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @template T | 
					
						
							|  |  |  |  * @template K | 
					
						
							|  |  |  |  * @template R | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class AsyncQueueEntry { | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {T} item the item | 
					
						
							|  |  |  | 	 * @param {Callback<R>} callback the callback | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	constructor(item, callback) { | 
					
						
							|  |  |  | 		this.item = item; | 
					
						
							|  |  |  | 		/** @type {typeof QUEUED_STATE | typeof PROCESSING_STATE | typeof DONE_STATE} */ | 
					
						
							|  |  |  | 		this.state = QUEUED_STATE; | 
					
						
							|  |  |  | 		this.callback = callback; | 
					
						
							|  |  |  | 		/** @type {Callback<R>[] | undefined} */ | 
					
						
							|  |  |  | 		this.callbacks = undefined; | 
					
						
							|  |  |  | 		this.result = undefined; | 
					
						
							|  |  |  | 		this.error = undefined; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @template T | 
					
						
							| 
									
										
										
										
											2018-09-26 16:27:09 +08:00
										 |  |  |  * @template K | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  |  * @template R | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class AsyncQueue { | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Object} options options object | 
					
						
							|  |  |  | 	 * @param {string=} options.name name of the queue | 
					
						
							|  |  |  | 	 * @param {number} options.parallelism how many items should be processed at once | 
					
						
							| 
									
										
										
										
											2018-09-26 16:27:09 +08:00
										 |  |  | 	 * @param {function(T): K=} options.getKey extract key from item | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 	 * @param {function(T, Callback<R>): void} options.processor async function to process items | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-09-26 16:27:09 +08:00
										 |  |  | 	constructor({ name, parallelism, processor, getKey }) { | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 		this._name = name; | 
					
						
							|  |  |  | 		this._parallelism = parallelism; | 
					
						
							|  |  |  | 		this._processor = processor; | 
					
						
							| 
									
										
										
										
											2018-09-26 16:27:09 +08:00
										 |  |  | 		this._getKey = | 
					
						
							|  |  |  | 			getKey || /** @type {(T) => K} */ (item => /** @type {any} */ (item)); | 
					
						
							| 
									
										
										
										
											2019-01-04 01:29:21 +08:00
										 |  |  | 		/** @type {Map<K, AsyncQueueEntry<T, K, R>>} */ | 
					
						
							|  |  |  | 		this._entries = new Map(); | 
					
						
							| 
									
										
										
										
											2019-01-04 21:22:22 +08:00
										 |  |  | 		/** @type {AsyncQueueEntry<T, K, R>[]} */ | 
					
						
							|  |  |  | 		this._queued = []; | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 		this._activeTasks = 0; | 
					
						
							|  |  |  | 		this._willEnsureProcessing = false; | 
					
						
							|  |  |  | 		this._stopped = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		this.hooks = { | 
					
						
							| 
									
										
										
										
											2018-12-18 05:05:08 +08:00
										 |  |  | 			/** @type {AsyncSeriesHook<[T]>} */ | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 			beforeAdd: new AsyncSeriesHook(["item"]), | 
					
						
							| 
									
										
										
										
											2018-12-18 05:05:08 +08:00
										 |  |  | 			/** @type {SyncHook<[T]>} */ | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 			added: new SyncHook(["item"]), | 
					
						
							| 
									
										
										
										
											2018-12-18 05:05:08 +08:00
										 |  |  | 			/** @type {AsyncSeriesHook<[T]>} */ | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 			beforeStart: new AsyncSeriesHook(["item"]), | 
					
						
							| 
									
										
										
										
											2018-12-18 05:05:08 +08:00
										 |  |  | 			/** @type {SyncHook<[T]>} */ | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 			started: new SyncHook(["item"]), | 
					
						
							| 
									
										
										
										
											2018-12-18 05:05:08 +08:00
										 |  |  | 			/** @type {SyncHook<[T, Error, R]>} */ | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 			result: new SyncHook(["item", "error", "result"]) | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		this._ensureProcessing = this._ensureProcessing.bind(this); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {T} item a item | 
					
						
							|  |  |  | 	 * @param {Callback<R>} callback callback function | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	add(item, callback) { | 
					
						
							|  |  |  | 		if (this._stopped) return callback(new Error("Queue was stopped")); | 
					
						
							|  |  |  | 		this.hooks.beforeAdd.callAsync(item, err => { | 
					
						
							|  |  |  | 			if (err) { | 
					
						
							|  |  |  | 				callback(err); | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-09-26 16:27:09 +08:00
										 |  |  | 			const key = this._getKey(item); | 
					
						
							| 
									
										
										
										
											2019-01-04 01:29:21 +08:00
										 |  |  | 			const entry = this._entries.get(key); | 
					
						
							|  |  |  | 			if (entry !== undefined) { | 
					
						
							|  |  |  | 				if (entry.state === DONE_STATE) { | 
					
						
							|  |  |  | 					process.nextTick(() => callback(entry.error, entry.result)); | 
					
						
							|  |  |  | 				} else if (entry.callbacks === undefined) { | 
					
						
							|  |  |  | 					entry.callbacks = [callback]; | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					entry.callbacks.push(callback); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-01-04 01:29:21 +08:00
										 |  |  | 			const newEntry = new AsyncQueueEntry(item, callback); | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 			if (this._stopped) { | 
					
						
							|  |  |  | 				this.hooks.added.call(item); | 
					
						
							|  |  |  | 				this._activeTasks++; | 
					
						
							| 
									
										
										
										
											2019-11-12 19:21:47 +08:00
										 |  |  | 				process.nextTick(() => | 
					
						
							|  |  |  | 					this._handleResult(newEntry, new Error("Queue was stopped")) | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2019-01-04 01:29:21 +08:00
										 |  |  | 				this._entries.set(key, newEntry); | 
					
						
							| 
									
										
										
										
											2019-01-04 21:22:22 +08:00
										 |  |  | 				this._queued.push(newEntry); | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 				if (this._willEnsureProcessing === false) { | 
					
						
							|  |  |  | 					this._willEnsureProcessing = true; | 
					
						
							| 
									
										
										
										
											2019-11-08 19:22:42 +08:00
										 |  |  | 					setImmediate(this._ensureProcessing); | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				this.hooks.added.call(item); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {T} item a item | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	invalidate(item) { | 
					
						
							| 
									
										
										
										
											2018-09-26 16:27:09 +08:00
										 |  |  | 		const key = this._getKey(item); | 
					
						
							| 
									
										
										
										
											2019-01-05 17:50:11 +08:00
										 |  |  | 		const entry = this._entries.get(key); | 
					
						
							| 
									
										
										
										
											2019-01-04 01:29:21 +08:00
										 |  |  | 		this._entries.delete(key); | 
					
						
							| 
									
										
										
										
											2019-01-05 17:50:11 +08:00
										 |  |  | 		if (entry.state === QUEUED_STATE) { | 
					
						
							|  |  |  | 			const idx = this._queued.indexOf(entry); | 
					
						
							|  |  |  | 			if (idx >= 0) { | 
					
						
							|  |  |  | 				this._queued.splice(idx, 1); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	stop() { | 
					
						
							|  |  |  | 		this._stopped = true; | 
					
						
							| 
									
										
										
										
											2019-01-04 21:22:22 +08:00
										 |  |  | 		const queue = this._queued; | 
					
						
							|  |  |  | 		this._queued = []; | 
					
						
							|  |  |  | 		for (const entry of queue) { | 
					
						
							| 
									
										
										
										
											2019-01-04 01:29:21 +08:00
										 |  |  | 			this._entries.delete(this._getKey(entry.item)); | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 			this._activeTasks++; | 
					
						
							| 
									
										
										
										
											2019-01-04 01:29:21 +08:00
										 |  |  | 			this._handleResult(entry, new Error("Queue was stopped")); | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	increaseParallelism() { | 
					
						
							|  |  |  | 		this._parallelism++; | 
					
						
							| 
									
										
										
										
											2020-07-29 17:14:26 +08:00
										 |  |  | 		/* istanbul ignore next */ | 
					
						
							| 
									
										
										
										
											2019-01-04 21:22:22 +08:00
										 |  |  | 		if (this._willEnsureProcessing === false && this._queued.length > 0) { | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 			this._willEnsureProcessing = true; | 
					
						
							| 
									
										
										
										
											2019-11-08 19:22:42 +08:00
										 |  |  | 			setImmediate(this._ensureProcessing); | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	decreaseParallelism() { | 
					
						
							|  |  |  | 		this._parallelism--; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {T} item an item | 
					
						
							|  |  |  | 	 * @returns {boolean} true, if the item is currently being processed | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	isProcessing(item) { | 
					
						
							| 
									
										
										
										
											2018-09-26 16:27:09 +08:00
										 |  |  | 		const key = this._getKey(item); | 
					
						
							| 
									
										
										
										
											2019-01-04 01:29:21 +08:00
										 |  |  | 		const entry = this._entries.get(key); | 
					
						
							|  |  |  | 		return entry !== undefined && entry.state === PROCESSING_STATE; | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {T} item an item | 
					
						
							|  |  |  | 	 * @returns {boolean} true, if the item is currently queued | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	isQueued(item) { | 
					
						
							| 
									
										
										
										
											2019-01-04 01:29:21 +08:00
										 |  |  | 		const key = this._getKey(item); | 
					
						
							|  |  |  | 		const entry = this._entries.get(key); | 
					
						
							|  |  |  | 		return entry !== undefined && entry.state === QUEUED_STATE; | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {T} item an item | 
					
						
							|  |  |  | 	 * @returns {boolean} true, if the item is currently queued | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	isDone(item) { | 
					
						
							| 
									
										
										
										
											2018-09-26 16:27:09 +08:00
										 |  |  | 		const key = this._getKey(item); | 
					
						
							| 
									
										
										
										
											2019-01-04 01:29:21 +08:00
										 |  |  | 		const entry = this._entries.get(key); | 
					
						
							|  |  |  | 		return entry !== undefined && entry.state === DONE_STATE; | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	_ensureProcessing() { | 
					
						
							| 
									
										
										
										
											2019-01-04 21:22:22 +08:00
										 |  |  | 		while (this._activeTasks < this._parallelism && this._queued.length > 0) { | 
					
						
							|  |  |  | 			const entry = this._queued.pop(); | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 			this._activeTasks++; | 
					
						
							| 
									
										
										
										
											2019-01-04 01:29:21 +08:00
										 |  |  | 			entry.state = PROCESSING_STATE; | 
					
						
							|  |  |  | 			this._startProcessing(entry); | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		this._willEnsureProcessing = false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2019-01-04 01:29:21 +08:00
										 |  |  | 	 * @param {AsyncQueueEntry<T, K, R>} entry the entry | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-01-04 01:29:21 +08:00
										 |  |  | 	_startProcessing(entry) { | 
					
						
							|  |  |  | 		this.hooks.beforeStart.callAsync(entry.item, err => { | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 			if (err) { | 
					
						
							| 
									
										
										
										
											2019-01-04 01:29:21 +08:00
										 |  |  | 				this._handleResult(entry, err); | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-01-10 22:07:03 +08:00
										 |  |  | 			let inCallback = false; | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 			try { | 
					
						
							| 
									
										
										
										
											2019-01-04 01:29:21 +08:00
										 |  |  | 				this._processor(entry.item, (e, r) => { | 
					
						
							| 
									
										
										
										
											2019-01-10 22:07:03 +08:00
										 |  |  | 					inCallback = true; | 
					
						
							| 
									
										
										
										
											2019-01-04 21:22:22 +08:00
										 |  |  | 					this._handleResult(entry, e, r); | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			} catch (err) { | 
					
						
							| 
									
										
										
										
											2019-01-10 22:07:03 +08:00
										 |  |  | 				if (inCallback) throw err; | 
					
						
							| 
									
										
										
										
											2019-01-04 01:29:21 +08:00
										 |  |  | 				this._handleResult(entry, err, null); | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-01-04 01:29:21 +08:00
										 |  |  | 			this.hooks.started.call(entry.item); | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2019-01-04 01:29:21 +08:00
										 |  |  | 	 * @param {AsyncQueueEntry<T, K, R>} entry the entry | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 	 * @param {Error=} err error, if any | 
					
						
							|  |  |  | 	 * @param {R=} result result, if any | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-01-04 01:29:21 +08:00
										 |  |  | 	_handleResult(entry, err, result) { | 
					
						
							|  |  |  | 		this.hooks.result.callAsync(entry.item, err, result, hookError => { | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 			const error = hookError || err; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-04 01:29:21 +08:00
										 |  |  | 			const callback = entry.callback; | 
					
						
							|  |  |  | 			const callbacks = entry.callbacks; | 
					
						
							|  |  |  | 			entry.state = DONE_STATE; | 
					
						
							|  |  |  | 			entry.callback = undefined; | 
					
						
							|  |  |  | 			entry.callbacks = undefined; | 
					
						
							|  |  |  | 			entry.result = result; | 
					
						
							|  |  |  | 			entry.error = error; | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 			this._activeTasks--; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-04 21:22:22 +08:00
										 |  |  | 			if (this._willEnsureProcessing === false && this._queued.length > 0) { | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 				this._willEnsureProcessing = true; | 
					
						
							| 
									
										
										
										
											2019-11-08 19:22:42 +08:00
										 |  |  | 				setImmediate(this._ensureProcessing); | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-12 19:21:47 +08:00
										 |  |  | 			if (inHandleResult++ > 3) { | 
					
						
							|  |  |  | 				process.nextTick(() => { | 
					
						
							| 
									
										
										
										
											2019-11-08 19:22:42 +08:00
										 |  |  | 					callback(error, result); | 
					
						
							| 
									
										
										
										
											2019-11-12 19:21:47 +08:00
										 |  |  | 					if (callbacks !== undefined) { | 
					
						
							|  |  |  | 						for (const callback of callbacks) { | 
					
						
							|  |  |  | 							callback(error, result); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				callback(error, result); | 
					
						
							|  |  |  | 				if (callbacks !== undefined) { | 
					
						
							|  |  |  | 					for (const callback of callbacks) { | 
					
						
							|  |  |  | 						callback(error, result); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2019-01-04 01:29:21 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2019-11-08 19:22:42 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-11-12 19:21:47 +08:00
										 |  |  | 			inHandleResult--; | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = AsyncQueue; |