Comparing version 1.1.0 to 1.1.1
{ | ||
"name": "contra", | ||
"description": "Asynchronous flow control with a functional taste to it", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"homepage": "https://github.com/bevacqua/contra", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -0,1 +1,6 @@ | ||
# 1.1.1 Down the Drain | ||
- Queue is an emitter | ||
- Queue emits `drain` events | ||
# 1.1.0 Obama Cares | ||
@@ -2,0 +7,0 @@ |
@@ -179,12 +179,25 @@ (function (Object) { | ||
// { name: 'queue', dependencies: ['core'] } | ||
var _queue = function (worker, concurrency) { | ||
function _queue (worker, concurrency) { | ||
var q = [], load = 0, max = concurrency || 1, paused; | ||
function _add (task, top, done) { | ||
var qq = _emitter({ | ||
push: _add(false), | ||
unshift: _add(true), | ||
pause: function () { paused = true; }, | ||
resume: function () { paused = false; cb(labor); }, | ||
pending: q | ||
}); | ||
if (Object.defineProperty && !Object.definePropertyPartial) { | ||
Object.defineProperty(qq, 'length', { get: function () { return q.length; } }); | ||
} | ||
function _add (top) { | ||
var m = top ? 'unshift' : 'push'; | ||
var tasks = a(task) ? task : [task]; | ||
tasks.forEach(function insert (t) { q[m]({ t: t, done: done }); }); | ||
cb(labor); | ||
return function manipulate (task, done) { | ||
var tasks = a(task) ? task : [task]; | ||
tasks.forEach(function insert (t) { q[m]({ t: t, done: done }); }); | ||
cb(labor); | ||
}; | ||
} | ||
function labor () { | ||
if (paused || load >= max || !q.length) { return; } | ||
if (paused || load >= max) { return; } | ||
if (!q.length) { qq.emit('drain'); return; } | ||
load++; | ||
@@ -199,17 +212,7 @@ var job = q.pop(); | ||
} | ||
var qq = { | ||
push: function (task, done) { _add(task, false, done); }, | ||
unshift: function (task, done) { _add(task, true, done); }, | ||
pause: function () { paused = true; }, | ||
resume: function () { paused = false; labor(); }, | ||
pending: q | ||
}; | ||
if (Object.defineProperty && !Object.definePropertyPartial) { | ||
Object.defineProperty(qq, 'length', { get: function () { return q.length; } }); | ||
} | ||
return qq; | ||
}; | ||
} | ||
// { name: 'outro', dependencies: ['core'] } | ||
var $ = { | ||
var λ = { | ||
curry: _curry, | ||
@@ -226,12 +229,12 @@ concurrent: _concurrent, | ||
$.each.series = _each(_series); | ||
$.map.series = _map(_series); | ||
$.filter.series = _filter(_series); | ||
λ.each.series = _each(_series); | ||
λ.map.series = _map(_series); | ||
λ.filter.series = _filter(_series); | ||
// cross-platform export | ||
if (typeof module !== 'undefined' && module.exports) { | ||
module.exports = $; | ||
module.exports = λ; | ||
} else { | ||
window.contra = $; | ||
window.contra = λ; | ||
} | ||
})(Object); |
@@ -1,1 +0,1 @@ | ||
!function(n){"use strict";function t(t){return"[object Array]"===n.prototype.toString.call(t)}function r(n){return Array.prototype.slice.call(n)}function e(n,t,r){n&&d(function(){n.apply(r||null,t||[])})}function u(n){function t(){r||(r=!0,n.apply(null,arguments))}var r;return t.discard=function(){r=!0},t}function i(n,t,r){var u=n.shift();return u?(r&&r.discard(),e(t,[u]),!0):void 0}function o(){var n=r(arguments),t=n.shift();return function(){var e=r(arguments);t.apply(t,n.concat(e))}}function f(n,t){function o(){var f=u(t);return u(function(){var t=r(arguments),u=n.shift();if(u){if(i(t,f))return;t.push(o()),e(u,t)}else e(f,arguments)})}o()()}function c(o,f){function c(){return u(function(){var n=l.shift(),t=r(arguments),u=o[n];if(a){if(i(t,s))return;p[a]=t.shift()}a=n,u?e(u,[c()]):e(s,[null,p])})}var a,s=u(f),l=n.keys(o),p=t(o)?[]:{};c()()}function a(o,f){function c(n){var t=u(function(){var u=r(arguments);i(u,a,t)||(l[n]=u.shift(),++p===h&&e(a,[null,l]))});return t}var a=u(f),s=n.keys(o),l=t(o)?[]:{},p=0,h=s.length;s.forEach(function(n){e(o[n],[c(n)])})}function s(r,e){return function(u,i,o){var f=n.keys(u),c=t(u)?[]:{};f.forEach(function(n){c[n]=function(t){i(u[n],t)}}),r(c,e?e(u,o):o)}}function l(n){function t(n,t){return function(n){t(n)}}return s(n,t)}function p(r){function e(r,e){return function(u,i){function o(n,t){return!!i[t]}function f(){var t={};return n.keys(r).forEach(function(n){o(null,n)&&(t[n]=r[n])}),t}return u?void e(u):void e(null,t(i)?r.filter(o):f())}}return s(r,e)}function h(n){var t=this,u={};return n.on=function(n,t){u[n]?u[n].push(t):u[n]=[t]},n.emit=function(){var n=r(arguments),i=n.shift(),o=u[i];if("error"===i&&!o)throw 1===n.length?n[0]:n;o&&o.forEach(function(r){e(r,n,t)})},n}var d,m="function"==typeof setImmediate;d="undefined"!=typeof process&&process.nextTick?m?setImmediate:process.nextTick:m?function(n){setImmediate(n)}:function(n){setTimeout(n,0)};var v=function(r,i){function o(n,r,u){var i=r?"unshift":"push",o=t(n)?n:[n];o.forEach(function(n){s[i]({t:n,done:u})}),e(f)}function f(){if(!(a||l>=p)&&s.length){l++;var n=s.pop();r(n.t,u(c.bind(null,n)))}}function c(n,t){l--,e(n.done,[t]),e(f)}var a,s=[],l=0,p=i||1,h={push:function(n,t){o(n,!1,t)},unshift:function(n,t){o(n,!0,t)},pause:function(){a=!0},resume:function(){a=!1,f()},pending:s};return n.defineProperty&&!n.definePropertyPartial&&n.defineProperty(h,"length",{get:function(){return s.length}}),h},y={curry:o,concurrent:a,series:c,waterfall:f,each:l(a),map:s(a),filter:p(a),queue:v,emitter:h};y.each.series=l(c),y.map.series=s(c),y.filter.series=p(c),"undefined"!=typeof module&&module.exports?module.exports=y:window.contra=y}(Object); | ||
!function(n){"use strict";function t(t){return"[object Array]"===n.prototype.toString.call(t)}function r(n){return Array.prototype.slice.call(n)}function e(n,t,r){n&&v(function(){n.apply(r||null,t||[])})}function u(n){function t(){r||(r=!0,n.apply(null,arguments))}var r;return t.discard=function(){r=!0},t}function i(n,t,r){var u=n.shift();return u?(r&&r.discard(),e(t,[u]),!0):void 0}function o(){var n=r(arguments),t=n.shift();return function(){var e=r(arguments);t.apply(t,n.concat(e))}}function f(n,t){function o(){var f=u(t);return u(function(){var t=r(arguments),u=n.shift();if(u){if(i(t,f))return;t.push(o()),e(u,t)}else e(f,arguments)})}o()()}function c(o,f){function c(){return u(function(){var n=l.shift(),t=r(arguments),u=o[n];if(a){if(i(t,s))return;p[a]=t.shift()}a=n,u?e(u,[c()]):e(s,[null,p])})}var a,s=u(f),l=n.keys(o),p=t(o)?[]:{};c()()}function a(o,f){function c(n){var t=u(function(){var u=r(arguments);i(u,a,t)||(l[n]=u.shift(),++p===d&&e(a,[null,l]))});return t}var a=u(f),s=n.keys(o),l=t(o)?[]:{},p=0,d=s.length;s.forEach(function(n){e(o[n],[c(n)])})}function s(r,e){return function(u,i,o){var f=n.keys(u),c=t(u)?[]:{};f.forEach(function(n){c[n]=function(t){i(u[n],t)}}),r(c,e?e(u,o):o)}}function l(n){function t(n,t){return function(n){t(n)}}return s(n,t)}function p(r){function e(r,e){return function(u,i){function o(n,t){return!!i[t]}function f(){var t={};return n.keys(r).forEach(function(n){o(null,n)&&(t[n]=r[n])}),t}return u?void e(u):void e(null,t(i)?r.filter(o):f())}}return s(r,e)}function d(n){var t=this,u={};return n.on=function(n,t){u[n]?u[n].push(t):u[n]=[t]},n.emit=function(){var n=r(arguments),i=n.shift(),o=u[i];if("error"===i&&!o)throw 1===n.length?n[0]:n;o&&o.forEach(function(r){e(r,n,t)})},n}function h(r,i){function o(n){var r=n?"unshift":"push";return function(n,u){var i=t(n)?n:[n];i.forEach(function(n){s[r]({t:n,done:u})}),e(f)}}function f(){if(!(a||l>=p)){if(!s.length)return void h.emit("drain");l++;var n=s.pop();r(n.t,u(c.bind(null,n)))}}function c(n,t){l--,e(n.done,[t]),e(f)}var a,s=[],l=0,p=i||1,h=d({push:o(!1),unshift:o(!0),pause:function(){a=!0},resume:function(){a=!1,e(f)},pending:s});return n.defineProperty&&!n.definePropertyPartial&&n.defineProperty(h,"length",{get:function(){return s.length}}),h}var v,m="function"==typeof setImmediate;v="undefined"!=typeof process&&process.nextTick?m?setImmediate:process.nextTick:m?function(n){setImmediate(n)}:function(n){setTimeout(n,0)};var y={curry:o,concurrent:a,series:c,waterfall:f,each:l(a),map:s(a),filter:p(a),queue:h,emitter:d};y.each.series=l(c),y.map.series=s(c),y.filter.series=p(c),"undefined"!=typeof module&&module.exports?module.exports=y:window.contra=y}(Object); |
{ | ||
"name": "contra", | ||
"description": "Asynchronous flow control with a functional taste to it", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"homepage": "https://github.com/bevacqua/contra", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -266,3 +266,3 @@ ![contra.png][logo] | ||
- `push(job[, done])` Array of jobs or an individual job object. Enqueue those jobs, resume processing. Optional callback to run when each job is completed | ||
- `unshift(job)` Array of jobs or an individual job object. Add jobs to the top of the queue, resume processing. Optional callback to run when each job is completed | ||
- `unshift(job[, done])` Array of jobs or an individual job object. Add jobs to the top of the queue, resume processing. Optional callback to run when each job is completed | ||
- `pending` Property. Jobs that haven't started processing yet | ||
@@ -272,2 +272,3 @@ - `length` Short-hand for `pending.length`, only works if getters can be defined | ||
- `resume()` Start processing jobs again | ||
- `on('drain', fn)` Execute `fn` whenever there's no more pending jobs and processing is requested. Processing can be requested using `resume`, `push`, or `unshift` | ||
@@ -359,2 +360,3 @@ ```js | ||
Arrays for [some][5], collections for [others][6]|Collections for **everyone**! | ||
`apply`|`curry` | ||
`parallel`|`concurrent` | ||
@@ -361,0 +363,0 @@ `mapSeries`|`map.series` |
@@ -179,12 +179,25 @@ (function (Object) { | ||
// { name: 'queue', dependencies: ['core'] } | ||
var _queue = function (worker, concurrency) { | ||
function _queue (worker, concurrency) { | ||
var q = [], load = 0, max = concurrency || 1, paused; | ||
function _add (task, top, done) { | ||
var qq = _emitter({ | ||
push: _add(false), | ||
unshift: _add(true), | ||
pause: function () { paused = true; }, | ||
resume: function () { paused = false; cb(labor); }, | ||
pending: q | ||
}); | ||
if (Object.defineProperty && !Object.definePropertyPartial) { | ||
Object.defineProperty(qq, 'length', { get: function () { return q.length; } }); | ||
} | ||
function _add (top) { | ||
var m = top ? 'unshift' : 'push'; | ||
var tasks = a(task) ? task : [task]; | ||
tasks.forEach(function insert (t) { q[m]({ t: t, done: done }); }); | ||
cb(labor); | ||
return function manipulate (task, done) { | ||
var tasks = a(task) ? task : [task]; | ||
tasks.forEach(function insert (t) { q[m]({ t: t, done: done }); }); | ||
cb(labor); | ||
}; | ||
} | ||
function labor () { | ||
if (paused || load >= max || !q.length) { return; } | ||
if (paused || load >= max) { return; } | ||
if (!q.length) { qq.emit('drain'); return; } | ||
load++; | ||
@@ -199,17 +212,7 @@ var job = q.pop(); | ||
} | ||
var qq = { | ||
push: function (task, done) { _add(task, false, done); }, | ||
unshift: function (task, done) { _add(task, true, done); }, | ||
pause: function () { paused = true; }, | ||
resume: function () { paused = false; labor(); }, | ||
pending: q | ||
}; | ||
if (Object.defineProperty && !Object.definePropertyPartial) { | ||
Object.defineProperty(qq, 'length', { get: function () { return q.length; } }); | ||
} | ||
return qq; | ||
}; | ||
} | ||
// { name: 'outro', dependencies: ['core'] } | ||
var $ = { | ||
var λ = { | ||
curry: _curry, | ||
@@ -226,12 +229,12 @@ concurrent: _concurrent, | ||
$.each.series = _each(_series); | ||
$.map.series = _map(_series); | ||
$.filter.series = _filter(_series); | ||
λ.each.series = _each(_series); | ||
λ.map.series = _map(_series); | ||
λ.filter.series = _filter(_series); | ||
// cross-platform export | ||
if (typeof module !== 'undefined' && module.exports) { | ||
module.exports = $; | ||
module.exports = λ; | ||
} else { | ||
window.contra = $; | ||
window.contra = λ; | ||
} | ||
})(Object); |
@@ -535,2 +535,19 @@ 'use strict'; | ||
}); | ||
it('should emit drain', function (done) { | ||
var ww; | ||
function w (job, done) { | ||
assert.fail(null, null, 'invoked worker'); | ||
} | ||
function d (err) { | ||
assert.fail(null, null, 'invoked job completion'); | ||
} | ||
function drained () { | ||
assert.falsy(ww); | ||
done(); | ||
} | ||
var q = λ.queue(w); | ||
q.on('drain', drained); | ||
q.push([], d); | ||
}); | ||
}); | ||
@@ -537,0 +554,0 @@ |
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
51579
1210
402