diff options
author | Alex Early <alexander.early@gmail.com> | 2018-07-08 16:58:36 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-08 16:58:36 -0700 |
commit | e4751178540a3c6e64598b93977481ec599704d2 (patch) | |
tree | dce5731bdb1076971d2e4a0a42fbe0d95c720185 /lib/internal/queue.js | |
parent | 6405b109fe60541ff42d7638ac891d321d6a7bb3 (diff) | |
download | async-e4751178540a3c6e64598b93977481ec599704d2.tar.gz |
ES6-ify codebase (#1553)
* cancelable foreach
* cancelable waterfall
* cancellable auto
* fix lint
* fix tests
* cancelable whilst/until/during/forever
* fix waterfall test. It WILL get there
* docs
* use rest params instead of slice
* clean up internals
* remove property func
* clarify uses of createTester
* happy path async funtions in asyncify
* stop using arguments
* DLL to class
* moar arrows
* fix merge issues
* remove forOwn
* moar arrows
* fix merge mistake
* even more arrows, what can stop him
* mo more fn.apply(null,...)
* remove more spurious uses of apply
* update lint config
* just when you thought there couldn't possibly be more arrows
* use eslint:recommended
* even less uses or aguments
* get rid of prototype cuteness
* fix concat tests
* fix more tests
Diffstat (limited to 'lib/internal/queue.js')
-rw-r--r-- | lib/internal/queue.js | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/lib/internal/queue.js b/lib/internal/queue.js index a421d2e..a811080 100644 --- a/lib/internal/queue.js +++ b/lib/internal/queue.js @@ -27,9 +27,7 @@ export default function queue(worker, concurrency, payload) { } if (data.length === 0 && q.idle()) { // call drain immediately if there are no tasks - return setImmediate(function() { - q.drain(); - }); + return setImmediate(() => q.drain()); } for (var i = 0, l = data.length; i < l; i++) { @@ -47,7 +45,7 @@ export default function queue(worker, concurrency, payload) { if (!processingScheduled) { processingScheduled = true; - setImmediate(function() { + setImmediate(() => { processingScheduled = false; q.process(); }); @@ -55,7 +53,7 @@ export default function queue(worker, concurrency, payload) { } function _next(tasks) { - return function(err){ + return function (err, ...args) { numRunning -= 1; for (var i = 0, l = tasks.length; i < l; i++) { @@ -68,7 +66,7 @@ export default function queue(worker, concurrency, payload) { workersList.splice(index, 1); } - task.callback.apply(task, arguments); + task.callback(err, ...args); if (err != null) { q.error(err, task.data); @@ -89,8 +87,8 @@ export default function queue(worker, concurrency, payload) { var isProcessing = false; var q = { _tasks: new DLL(), - concurrency: concurrency, - payload: payload, + concurrency, + payload, saturated: noop, unsaturated:noop, buffer: concurrency / 4, @@ -99,20 +97,20 @@ export default function queue(worker, concurrency, payload) { error: noop, started: false, paused: false, - push: function (data, callback) { + push (data, callback) { _insert(data, false, callback); }, - kill: function () { + kill () { q.drain = noop; q._tasks.empty(); }, - unshift: function (data, callback) { + unshift (data, callback) { _insert(data, true, callback); }, - remove: function (testFn) { + remove (testFn) { q._tasks.remove(testFn); }, - process: function () { + process () { // Avoid trying to start too many processing operations. This can occur // when callbacks resolve synchronously (#1267). if (isProcessing) { @@ -145,22 +143,22 @@ export default function queue(worker, concurrency, payload) { } isProcessing = false; }, - length: function () { + length () { return q._tasks.length; }, - running: function () { + running () { return numRunning; }, - workersList: function () { + workersList () { return workersList; }, - idle: function() { + idle() { return q._tasks.length + numRunning === 0; }, - pause: function () { + pause () { q.paused = true; }, - resume: function () { + resume () { if (q.paused === false) { return; } q.paused = false; setImmediate(q.process); |