queue-async
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -1,1 +0,1 @@ | ||
import queue from "../index"; queue.version = "1.1.0"; export default queue; | ||
import queue from "../index"; queue.version = "1.1.1"; export default queue; |
@@ -8,27 +8,29 @@ (function (global, factory) { | ||
var slice = [].slice; | ||
var running = {}; | ||
function noop() {} | ||
function queue(parallelism) { | ||
var running = {}; | ||
var success = [null]; | ||
function newQueue(parallelism) { | ||
if (!(parallelism >= 1)) throw new Error; | ||
var q, | ||
tasks = [], | ||
started = 0, // number of tasks that have been started (and perhaps finished) | ||
active = 0, // number of tasks currently being executed (started but not finished) | ||
remaining = 0, // number of tasks not yet finished | ||
popping, // inside a synchronous task callback? | ||
error = null, | ||
waiting = 0, | ||
active = 0, | ||
ended = 0, | ||
starting, // inside a synchronous task callback? | ||
error, | ||
callback = noop, | ||
callbackAll; | ||
callbackAll = true; | ||
parallelism = arguments.length ? +parallelism : Infinity; | ||
function pop() { | ||
while (popping = started < tasks.length && active < parallelism) { | ||
var i = started++, | ||
function start() { | ||
if (starting) return; // let the current task complete | ||
while (starting = waiting && active < parallelism) { | ||
var i = ended + active, | ||
t = tasks[i], | ||
j = t.length - 1, | ||
c = t[j]; | ||
tasks[i] = running; | ||
++active; | ||
t[j] = finished(i); | ||
tasks[i] = running, --waiting, ++active; | ||
t[j] = end(i); | ||
c.apply(null, t); | ||
@@ -38,16 +40,15 @@ } | ||
function finished(i) { | ||
function end(i) { | ||
return function(e, r) { | ||
if (tasks[i] !== running) throw new Error; | ||
tasks[i] = null; | ||
--active; | ||
if (error != null) return; | ||
if (tasks[i] !== running) throw new Error; // detect multiple callbacks | ||
tasks[i] = null, --active, ++ended; | ||
if (error != null) return; // only report the first error | ||
if (e != null) { | ||
error = e; // ignore new tasks and squelch active callbacks | ||
started = remaining = NaN; // stop queued tasks from starting | ||
waiting = NaN; // stop queued tasks from starting | ||
notify(); | ||
} else { | ||
tasks[i] = r; | ||
if (--remaining) popping || pop(); | ||
else notify(); | ||
if (waiting) start(); | ||
else if (!active) notify(); | ||
} | ||
@@ -57,10 +58,6 @@ }; | ||
function check() { | ||
if (callback !== noop) throw new Error; | ||
} | ||
function notify() { | ||
if (error != null) callback(error); | ||
else if (callbackAll) callback(error, tasks); | ||
else callback.apply(null, [error].concat(tasks)); | ||
else if (callbackAll) callback(null, tasks); | ||
else callback.apply(null, success.concat(tasks)); | ||
} | ||
@@ -70,22 +67,19 @@ | ||
defer: function(f) { | ||
check(); | ||
if (!error) { | ||
var t = slice.call(arguments, 1); | ||
t.push(f); | ||
tasks.push(t); | ||
++remaining; | ||
pop(); | ||
} | ||
if (callback !== noop) throw new Error; | ||
var t = slice.call(arguments, 1); | ||
t.push(f); | ||
tasks.push(t), ++waiting; | ||
start(); | ||
return q; | ||
}, | ||
await: function(f) { | ||
check(); | ||
if (callback !== noop) throw new Error; | ||
callback = f, callbackAll = false; | ||
if (!remaining) notify(); | ||
if (!waiting && !active) notify(); | ||
return q; | ||
}, | ||
awaitAll: function(f) { | ||
check(); | ||
if (callback !== noop) throw new Error; | ||
callback = f, callbackAll = true; | ||
if (!remaining) notify(); | ||
if (!waiting && !active) notify(); | ||
return q; | ||
@@ -96,6 +90,10 @@ } | ||
queue.version = "1.1.0"; | ||
function queue(parallelism) { | ||
return newQueue(arguments.length ? +parallelism : Infinity); | ||
} | ||
queue.version = "1.1.1"; | ||
return queue; | ||
})); |
@@ -1,1 +0,1 @@ | ||
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define("queue",e):n.queue=e()}(this,function(){"use strict";function n(){}function e(e){function r(){for(;c=s<p.length&&e>d;){var n=s++,t=p[n],r=t.length-1,i=t[r];p[n]=u,++d,t[r]=o(n),i.apply(null,t)}}function o(n){return function(e,t){if(p[n]!==u)throw new Error;p[n]=null,--d,null==w&&(null!=e?(w=e,s=h=NaN,l()):(p[n]=t,--h?c||r():l()))}}function i(){if(g!==n)throw new Error}function l(){null!=w?g(w):a?g(w,p):g.apply(null,[w].concat(p))}var f,c,a,p=[],s=0,d=0,h=0,w=null,g=n;return e=arguments.length?+e:1/0,f={defer:function(n){if(i(),!w){var e=t.call(arguments,1);e.push(n),p.push(e),++h,r()}return f},await:function(n){return i(),g=n,a=!1,h||l(),f},awaitAll:function(n){return i(),g=n,a=!0,h||l(),f}}}var t=[].slice,u={};return e.version="1.1.0",e}); | ||
!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define("queue",r):n.queue=r()}(this,function(){"use strict";function n(){}function r(r){function e(){if(!c)for(;c=p&&r>s;){var n=h+s,e=w[n],t=e.length-1,o=e[t];w[n]=u,--p,++s,e[t]=i(n),o.apply(null,e)}}function i(n){return function(r,t){if(w[n]!==u)throw new Error;w[n]=null,--s,++h,null==a&&(null!=r?(a=r,p=NaN,f()):(w[n]=t,p?e():s||f()))}}function f(){null!=a?d(a):m?d(null,w):d.apply(null,o.concat(w))}if(!(r>=1))throw new Error;var l,c,a,w=[],p=0,s=0,h=0,d=n,m=!0;return l={defer:function(r){if(d!==n)throw new Error;var u=t.call(arguments,1);return u.push(r),w.push(u),++p,e(),l},await:function(r){if(d!==n)throw new Error;return d=r,m=!1,p||s||f(),l},awaitAll:function(r){if(d!==n)throw new Error;return d=r,m=!0,p||s||f(),l}}}function e(n){return r(arguments.length?+n:1/0)}var t=[].slice,u={},o=[null];return e.version="1.1.1",e}); |
{ | ||
"name": "queue-async", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "A little helper for asynchronous JavaScript.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -1,28 +0,29 @@ | ||
var slice = [].slice, | ||
running = {}; | ||
import {slice} from "./array"; | ||
import noop from "./noop"; | ||
function noop() {} | ||
var running = {}, | ||
success = [null]; | ||
export default function(parallelism) { | ||
function newQueue(parallelism) { | ||
if (!(parallelism >= 1)) throw new Error; | ||
var q, | ||
tasks = [], | ||
started = 0, // number of tasks that have been started (and perhaps finished) | ||
active = 0, // number of tasks currently being executed (started but not finished) | ||
remaining = 0, // number of tasks not yet finished | ||
popping, // inside a synchronous task callback? | ||
error = null, | ||
waiting = 0, | ||
active = 0, | ||
ended = 0, | ||
starting, // inside a synchronous task callback? | ||
error, | ||
callback = noop, | ||
callbackAll; | ||
callbackAll = true; | ||
parallelism = arguments.length ? +parallelism : Infinity; | ||
function pop() { | ||
while (popping = started < tasks.length && active < parallelism) { | ||
var i = started++, | ||
function start() { | ||
if (starting) return; // let the current task complete | ||
while (starting = waiting && active < parallelism) { | ||
var i = ended + active, | ||
t = tasks[i], | ||
j = t.length - 1, | ||
c = t[j]; | ||
tasks[i] = running; | ||
++active; | ||
t[j] = finished(i); | ||
tasks[i] = running, --waiting, ++active; | ||
t[j] = end(i); | ||
c.apply(null, t); | ||
@@ -32,16 +33,15 @@ } | ||
function finished(i) { | ||
function end(i) { | ||
return function(e, r) { | ||
if (tasks[i] !== running) throw new Error; | ||
tasks[i] = null; | ||
--active; | ||
if (error != null) return; | ||
if (tasks[i] !== running) throw new Error; // detect multiple callbacks | ||
tasks[i] = null, --active, ++ended; | ||
if (error != null) return; // only report the first error | ||
if (e != null) { | ||
error = e; // ignore new tasks and squelch active callbacks | ||
started = remaining = NaN; // stop queued tasks from starting | ||
waiting = NaN; // stop queued tasks from starting | ||
notify(); | ||
} else { | ||
tasks[i] = r; | ||
if (--remaining) popping || pop(); | ||
else notify(); | ||
if (waiting) start(); | ||
else if (!active) notify(); | ||
} | ||
@@ -51,10 +51,6 @@ }; | ||
function check() { | ||
if (callback !== noop) throw new Error; | ||
} | ||
function notify() { | ||
if (error != null) callback(error); | ||
else if (callbackAll) callback(error, tasks); | ||
else callback.apply(null, [error].concat(tasks)); | ||
else if (callbackAll) callback(null, tasks); | ||
else callback.apply(null, success.concat(tasks)); | ||
} | ||
@@ -64,22 +60,19 @@ | ||
defer: function(f) { | ||
check(); | ||
if (!error) { | ||
var t = slice.call(arguments, 1); | ||
t.push(f); | ||
tasks.push(t); | ||
++remaining; | ||
pop(); | ||
} | ||
if (callback !== noop) throw new Error; | ||
var t = slice.call(arguments, 1); | ||
t.push(f); | ||
tasks.push(t), ++waiting; | ||
start(); | ||
return q; | ||
}, | ||
await: function(f) { | ||
check(); | ||
if (callback !== noop) throw new Error; | ||
callback = f, callbackAll = false; | ||
if (!remaining) notify(); | ||
if (!waiting && !active) notify(); | ||
return q; | ||
}, | ||
awaitAll: function(f) { | ||
check(); | ||
if (callback !== noop) throw new Error; | ||
callback = f, callbackAll = true; | ||
if (!remaining) notify(); | ||
if (!waiting && !active) notify(); | ||
return q; | ||
@@ -89,1 +82,5 @@ } | ||
} | ||
export default function(parallelism) { | ||
return newQueue(arguments.length ? +parallelism : Infinity); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
13848
12
0
159