* Processes the provided item. * @param {T} item an item * @param {Callback<R>} callback callback function * @returns {void}
(item, callback)
| 158 | * @returns {void} |
| 159 | */ |
| 160 | add(item, callback) { |
| 161 | if (this._stopped) return callback(new WebpackError("Queue was stopped")); |
| 162 | this.hooks.beforeAdd.callAsync(item, (err) => { |
| 163 | if (err) { |
| 164 | callback( |
| 165 | makeWebpackError(err, `AsyncQueue(${this._name}).hooks.beforeAdd`) |
| 166 | ); |
| 167 | return; |
| 168 | } |
| 169 | const key = this._getKey(item); |
| 170 | const entry = this._entries.get(key); |
| 171 | if (entry !== undefined) { |
| 172 | if (entry.state === DONE_STATE) { |
| 173 | if (inHandleResult++ > 3) { |
| 174 | process.nextTick(() => callback(entry.error, entry.result)); |
| 175 | } else { |
| 176 | callback(entry.error, entry.result); |
| 177 | } |
| 178 | inHandleResult--; |
| 179 | } else if (entry.callbacks === undefined) { |
| 180 | entry.callbacks = [callback]; |
| 181 | } else { |
| 182 | entry.callbacks.push(callback); |
| 183 | } |
| 184 | return; |
| 185 | } |
| 186 | const newEntry = new AsyncQueueEntry(item, callback); |
| 187 | if (this._stopped) { |
| 188 | this.hooks.added.call(item); |
| 189 | this._root._activeTasks++; |
| 190 | process.nextTick(() => |
| 191 | this._handleResult(newEntry, new WebpackError("Queue was stopped")) |
| 192 | ); |
| 193 | } else { |
| 194 | this._entries.set(key, newEntry); |
| 195 | this._queued.enqueue(newEntry); |
| 196 | const root = this._root; |
| 197 | root._needProcessing = true; |
| 198 | if (root._willEnsureProcessing === false) { |
| 199 | root._willEnsureProcessing = true; |
| 200 | setImmediate(root._ensureProcessing); |
| 201 | } |
| 202 | this.hooks.added.call(item); |
| 203 | } |
| 204 | }); |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * Processes the provided item. |
nothing calls this directly
no test coverage detected