asynquence
Advanced tools
Comparing version 0.4.1-a to 0.5.0-a
/*! asynquence | ||
v0.4.1-a (c) Kyle Simpson | ||
v0.5.0-a (c) Kyle Simpson | ||
MIT License: http://getify.mit-license.org | ||
*/ | ||
!function(n,e,t){"undefined"!=typeof module&&module.exports?module.exports=t():"function"==typeof define&&define.amd?define(t):e[n]=t(n,e)}("ASQ",this,function(n,e){"use strict";function t(n){return"undefined"!=typeof setImmediate?setImmediate(n):setTimeout(n,0)}function u(){function n(){P?a():Q||(Q=t(a))}function e(){throw 1===F.length?F[0]:F}function a(){var t,u;if(Q=null,delete G.unpause,P)clearTimeout(Q),Q=null,z.length=B.length=D.length=F.length=0;else if(C)for(0!==B.length||M||(M=!0,e());B.length;){M=!0,t=B.shift();try{t.apply(b,F)}catch(r){h(r)?F=F.concat(r):(F.push(r),r.stack&&F.push(r.stack)),0===B.length&&e()}}else if(W&&z.length>0){W=!1,t=z.shift(),u=D.slice(),D.length=0,u.unshift(l());try{t.apply(b,u)}catch(r){h(r)?F=F.concat(r):F.push(r),C=!0,n()}}}function l(){function e(){C||P||W||(W=!0,D.push.apply(D,arguments),F.length=0,n())}return e.fail=function(){C||P||W||(C=!0,D.length=0,F.push.apply(F,arguments),n())},e.abort=function(){C||P||(W=!1,P=!0,D.length=F.length=0,n())},e.errfcb=function(n){n?e.fail(n):e.apply(b,d.call(arguments,1))},e}function o(n,e,u){function r(){clearTimeout(g),g=_=q=s=null}function a(){return y?l():(g||(g=t(l)),void 0)}function l(){if(!(C||P||v)){var e=[];g=null,m?(n.fail.apply(b,s),r()):y?(n.abort(),r()):i()&&(v=!0,_.forEach(function(n,t){e.push(q["s"+t])}),n.apply(b,e),r())}}function i(){if(0!==_.length){var n=!0;return _.some(function(e){return null===e?(n=!1,!0):void 0}),n}}function c(){function n(){if(!(C||P||m||y||v||_[e])){var n=p.apply(b,arguments);q["s"+e]=n.length>1?n:n[0],_[e]=!0,a()}}var e=_.length;return n.fail=function(){C||P||m||y||v||_[e]||(m=!0,s=d.call(arguments),a())},n.abort=function(){C||P||m||y||v||(y=!0,l())},n.errfcb=function(e){e?n.fail(e):n.apply(b,d.call(arguments,1))},_[e]=null,n}var f,o,s,g,m=!1,y=!1,v=!1,_=[],q={};e.some(function(n){if(m||y)return!0;f=u.slice(),f.unshift(c());try{n.apply(b,f)}catch(e){return o=e,m=!0,!0}}),o&&(h(o)?n.fail.apply(b,o):n.fail(o))}function y(){return C||P||0===arguments.length?G:(z.push.apply(z,f(arguments,c)),n(),G)}function v(){return P||0===arguments.length?G:(B.push.apply(B,arguments),n(),G)}function _(){if(C||P||0===arguments.length)return G;var n=d.call(arguments);return y(function(e){var t=d.call(arguments,1);o(e,n,t)}),G}function q(){return P||0===arguments.length?G:(d.call(arguments).forEach(function(n){y(function(e){n.apply(b,d.call(arguments,1)),e()}).or(n.fail)}),G)}function k(){return C||P||0===arguments.length?G:(d.call(arguments).forEach(function(n){var e;g(n)&&(n.defer(),"next"in n&&(n.then(function(){e.apply(b,arguments)}).or(function(){e.fail.apply(b,arguments)}),n=u(function(n){e=n}).defer(),e=function(){n=u.apply(b,arguments).defer()},e.fail=function(){var e=d.call(arguments);n=u(function(n){n.fail.apply(b,e)}).defer()})),y(function(e){var t=n;g(n)||(t=n.apply(b,d.call(arguments,1))),t.pipe(e)})}),G)}function A(){return C||P||0===arguments.length?G:(d.call(f(arguments,i)).forEach(function(n){y(function(e){var t=n.apply(b,d.call(arguments,1));h(t)||(t=p(t)),e.apply(b,t)})}),G)}function E(){function n(n){return function(){n.apply(b,h(arguments[0])?arguments[0]:arguments)}}return C||P||0===arguments.length?G:(d.call(arguments).forEach(function(e){y(function(t){var u=e;"function"!=typeof e||"then"in e||(u=e.apply(b,d.call(arguments,1))),u.then(n(t),n(t.fail))})}),G)}function x(){var n;return A(function(){return n?n.apply(b,arguments):n=u.apply(b,arguments).defer(),p.apply(b,arguments)}),v(function(){if(n)n.fail.apply(b,arguments);else{var e=d.call(arguments);n=u().then(function(n){n.fail.apply(b,e)}).defer()}}),u().then(function(e){n?n.pipe(e):n=e}).defer()}function j(){return C?G:(P=!0,a(),G)}function O(){var n;return s={then_queue:z.slice(),or_queue:B.slice()},n=u(),s=null,n}function S(){D.push.apply(D,arguments),Q===!0&&(Q=null),n()}function T(){return B.push(function(){}),G}function w(n,e){var t=arguments.length>1;switch(n){case"seq_error":if(!t)return C;C=e;break;case"seq_aborted":if(!t)return P;P=e;break;case"then_ready":if(!t)return W;W=e;break;case"then_queue":return z;case"or_queue":return B;case"sequence_messages":return D;case"sequence_errors":return F}}function I(){Object.keys(m).forEach(function(n){G[n]=m[n](G,w)})}var Q,C=!1,M=!1,P=!1,W=!0,z=[],B=[],D=[],F=[],G=r({then:y,or:v,gate:_,pipe:q,seq:k,val:A,promise:E,fork:x,abort:j,duplicate:O,defer:T});return I(),s&&(z=s.then_queue.slice(0),B=s.or_queue.slice(0),G.unpause=S,Q=!0),G.then.apply(b,f(arguments,c)),G}function r(n){return Object.defineProperty(n,v,{enumerable:!1,value:!0})}function a(n){return null!=n&&"object"==typeof n&&n[v]}function l(n,e){return d.call(e).slice(1,n+1)}function i(n){return p.apply(b,l(n,arguments))}function c(n){arguments[n+1].apply(b,l(n,arguments))}function f(n,e){var t,u;for(n=d.call(n),t=0;t<n.length;t++)if(h(n[t]))n[t]=e.bind.apply(e,[null,n[t].length].concat(n[t]));else if("function"!=typeof n[t]){for(u=t+1;u<n.length&&("function"!=typeof n[u]&&!a(n[u]));u++);n.splice(t,u-t,e.bind.apply(e,[null,u-t].concat(n.slice(t,u))))}return n}var o,s,p,g,h,m={},y=(e||{})[n],d=[].slice,v="__ASQ__",b=Object.create(null);return o=u,o.extend=function(n,e){return~["then","or","gate","pipe","seq","val","promise","fork","abort","duplicate","defer"].indexOf(n)||(m[n]=e),o},o.messages=p=function(){var n=d.call(arguments);return r(n)},o.isSequence=g=function(n){return a(n)&&!Array.isArray(n)},o.isMessageWrapper=h=function(n){return a(n)&&Array.isArray(n)},o.unpause=function(n){return n.unpause&&n.unpause(),n},o.noConflict=function(){return e&&(e[n]=y),o},o}); | ||
!function(n,e,t){"undefined"!=typeof module&&module.exports?module.exports=t():"function"==typeof define&&define.amd?define(t):e[n]=t(n,e)}("ASQ",this,function(n,e){"use strict";function t(){function n(n,e){this.fn=n,this.self=e,this.next=void 0}var e,t,u;return{add:function(r,a){u=new n(r,a),t?t.next=u:e=u,t=u,u=void 0},drain:function(){for(;e;)e.fn.call(e.self),e=e.next;s=t=e}}}function u(n,e){p.add(n,e),s||(s=g(p.drain))}function r(){function n(){P?t():Q||(Q=u(t))}function e(){throw 1===F.length?F[0]:F}function t(){var t,u;if(Q=null,delete G.unpause,P)clearTimeout(Q),Q=null,z.length=B.length=D.length=F.length=0;else if(C)for(0!==B.length||M||(M=!0,e());B.length;){M=!0,t=B.shift();try{t.apply(x,F)}catch(r){v(r)?F=F.concat(r):(F.push(r),r.stack&&F.push(r.stack)),0===B.length&&e()}}else if(W&&z.length>0){W=!1,t=z.shift(),u=D.slice(),D.length=0,u.unshift(i());try{t.apply(x,u)}catch(r){v(r)?F=F.concat(r):F.push(r),C=!0,n()}}}function i(){function e(){C||P||W||(W=!0,D.push.apply(D,arguments),F.length=0,n())}return e.fail=function(){C||P||W||(C=!0,D.length=0,F.push.apply(F,arguments),n())},e.abort=function(){C||P||(W=!1,P=!0,D.length=F.length=0,n())},e.errfcb=function(n){n?e.fail(n):e.apply(x,q.call(arguments,1))},e}function l(n,e,t){function r(){clearTimeout(p),p=d=b=s=null}function a(){return h?i():(p||(p=u(i)),void 0)}function i(){if(!(C||P||m)){var e=[];p=null,g?(n.fail.apply(x,s),r()):h?(n.abort(),r()):l()&&(m=!0,d.forEach(function(n,t){e.push(b["s"+t])}),n.apply(x,e),r())}}function l(){if(0!==d.length){var n=!0;return d.some(function(e){return null===e?(n=!1,!0):void 0}),n}}function c(){function n(){if(!(C||P||g||h||m||d[e])){var n=y.apply(x,arguments);b["s"+e]=n.length>1?n:n[0],d[e]=!0,a()}}var e=d.length;return n.fail=function(){C||P||g||h||m||d[e]||(g=!0,s=q.call(arguments),a())},n.abort=function(){C||P||g||h||m||(h=!0,i())},n.errfcb=function(e){e?n.fail(e):n.apply(x,q.call(arguments,1))},d[e]=null,n}var f,o,s,p,g=!1,h=!1,m=!1,d=[],b={};e.some(function(n){if(g||h)return!0;f=t.slice(),f.unshift(c());try{n.apply(x,f)}catch(e){return o=e,g=!0,!0}}),o&&(v(o)?n.fail.apply(x,o):n.fail(o))}function s(){return C||P||0===arguments.length?G:(z.push.apply(z,o(arguments,f)),n(),G)}function p(){return P||0===arguments.length?G:(B.push.apply(B,arguments),n(),G)}function g(){if(C||P||0===arguments.length)return G;var n=q.call(arguments);return s(function(e){var t=q.call(arguments,1);l(e,n,t)}),G}function h(){return P||0===arguments.length?G:(q.call(arguments).forEach(function(n){s(function(e){n.apply(x,q.call(arguments,1)),e()}).or(n.fail)}),G)}function _(){return C||P||0===arguments.length?G:(q.call(arguments).forEach(function(n){var e;d(n)&&(n.defer(),"next"in n&&(n.then(function(){e.apply(x,arguments)}).or(function(){e.fail.apply(x,arguments)}),n=r(function(n){e=n}).defer(),e=function(){n=r.apply(x,arguments).defer()},e.fail=function(){var e=q.call(arguments);n=r(function(n){n.fail.apply(x,e)}).defer()})),s(function(e){var t=n;d(n)||(t=n.apply(x,q.call(arguments,1))),t.pipe(e)})}),G)}function k(){return C||P||0===arguments.length?G:(q.call(o(arguments,c)).forEach(function(n){s(function(e){var t=n.apply(x,q.call(arguments,1));v(t)||(t=y(t)),e.apply(x,t)})}),G)}function A(){function n(n){return function(){n.apply(x,v(arguments[0])?arguments[0]:arguments)}}return C||P||0===arguments.length?G:(q.call(arguments).forEach(function(e){s(function(t){var u=e;"function"!=typeof e||"then"in e||(u=e.apply(x,q.call(arguments,1))),u.then(n(t),n(t.fail))})}),G)}function E(){var n;return k(function(){return n?n.apply(x,arguments):n=r.apply(x,arguments).defer(),y.apply(x,arguments)}),p(function(){if(n)n.fail.apply(x,arguments);else{var e=q.call(arguments);n=r().then(function(n){n.fail.apply(x,e)}).defer()}}),r().then(function(e){n?n.pipe(e):n=e}).defer()}function j(){return C?G:(P=!0,t(),G)}function w(){var n;return m={then_queue:z.slice(),or_queue:B.slice()},n=r(),m=null,n}function O(){D.push.apply(D,arguments),Q===!0&&(Q=null),n()}function S(){return B.push(function(){}),G}function T(n,e){var t=arguments.length>1;switch(n){case"seq_error":if(!t)return C;C=e;break;case"seq_aborted":if(!t)return P;P=e;break;case"then_ready":if(!t)return W;W=e;break;case"then_queue":return z;case"or_queue":return B;case"sequence_messages":return D;case"sequence_errors":return F}}function I(){Object.keys(b).forEach(function(n){G[n]=b[n](G,T)})}var Q,C=!1,M=!1,P=!1,W=!0,z=[],B=[],D=[],F=[],G=a({then:s,or:p,gate:g,pipe:h,seq:_,val:k,promise:A,fork:E,abort:j,duplicate:w,defer:S});return I(),m&&(z=m.then_queue.slice(),B=m.or_queue.slice(),G.unpause=O,Q=!0),G.then.apply(x,o(arguments,f)),G}function a(n){return Object.defineProperty(n,k,{enumerable:!1,value:!0})}function i(n){return null!=n&&"object"==typeof n&&n[k]}function l(n,e){return q.call(e).slice(1,n+1)}function c(n){return y.apply(x,l(n,arguments))}function f(n){arguments[n+1].apply(x,l(n,arguments))}function o(n,e){var t,u;for(n=q.call(n),t=0;t<n.length;t++)if(v(n[t]))n[t]=e.bind.apply(e,[null,n[t].length].concat(n[t]));else if("function"!=typeof n[t]){for(u=t+1;u<n.length&&("function"!=typeof n[u]&&!i(n[u]));u++);n.splice(t,u-t,e.bind.apply(e,[null,u-t].concat(n.slice(t,u))))}return n}var s,p,g="undefined"!=typeof setImmediate?function(n){return setImmediate(n)}:setTimeout;p=t();var h,m,y,d,v,b={},_=(e||{})[n],q=[].slice,k="__ASQ__",x=Object.create(null);return h=r,h.failed=function(){var n=h.messages.apply(x,arguments);return r(function(){throw n})},h.extend=function(n,e){return~["then","or","gate","pipe","seq","val","promise","fork","abort","duplicate","defer"].indexOf(n)||(b[n]=e),h},h.messages=y=function(){var n=q.call(arguments);return a(n)},h.isSequence=d=function(n){return i(n)&&!Array.isArray(n)},h.isMessageWrapper=v=function(n){return i(n)&&Array.isArray(n)},h.unpause=function(n){return n.unpause&&n.unpause(),n},h.noConflict=function(){return e&&(e[n]=_),h},h}); |
/*! asynquence | ||
v0.4.1-a (c) Kyle Simpson | ||
v0.5.0-a (c) Kyle Simpson | ||
MIT License: http://getify.mit-license.org | ||
@@ -13,8 +13,49 @@ */ | ||
function schedule(fn) { | ||
return (typeof setImmediate !== "undefined") ? | ||
setImmediate(fn) : setTimeout(fn,0) | ||
; | ||
var cycle, scheduling_queue, | ||
timer = (typeof setImmediate !== "undefined") ? | ||
function timer(fn) { return setImmediate(fn); } : | ||
setTimeout | ||
; | ||
// Note: using a queue instead of array for efficiency | ||
function Queue() { | ||
var first, last, item; | ||
function Item(fn,self) { | ||
this.fn = fn; | ||
this.self = self; | ||
this.next = void 0; | ||
} | ||
return { | ||
add: function add(fn,self) { | ||
item = new Item(fn,self); | ||
if (last) { | ||
last.next = item; | ||
} | ||
else { | ||
first = item; | ||
} | ||
last = item; | ||
item = void 0; | ||
}, | ||
drain: function drain(self) { | ||
while (first) { | ||
first.fn.call(first.self); | ||
first = first.next; | ||
} | ||
cycle = last = first; | ||
} | ||
}; | ||
} | ||
scheduling_queue = Queue(); | ||
function schedule(fn,self) { | ||
scheduling_queue.add(fn,self); | ||
if (!cycle) { | ||
cycle = timer(scheduling_queue.drain); | ||
} | ||
} | ||
function createSequence() { | ||
@@ -653,4 +694,4 @@ | ||
if (template) { | ||
then_queue = template.then_queue.slice(0); | ||
or_queue = template.or_queue.slice(0); | ||
then_queue = template.then_queue.slice(); | ||
or_queue = template.or_queue.slice(); | ||
@@ -770,2 +811,7 @@ // templating a sequence starts it out paused | ||
public_api.failed = function publicAPI$failed() { | ||
var args = public_api.messages.apply(ø,arguments); | ||
return createSequence(function $failed$(){ throw args; }); | ||
}; | ||
public_api.extend = function publicAPI$extend(name,build) { | ||
@@ -772,0 +818,0 @@ // reserved API override not allowed |
{ | ||
"name": "asynquence", | ||
"version": "0.4.1-a", | ||
"version": "0.5.0-a", | ||
"description": "asynquence: promise-style async sequence flow-control", | ||
@@ -5,0 +5,0 @@ "main": "./asq.js", |
# asynquence | ||
A tiny (**~2.0k** minzipped) lib for promise-style async sequence flow-control. | ||
A tiny (**~2.2k** minzipped) lib for promise-style async sequence flow-control. | ||
@@ -17,3 +17,3 @@ ## Explanation | ||
* [CSP-style coroutine concurrency](https://gist.github.com/getify/10172207) via [`runner(..)` contrib plugin](https://github.com/getify/asynquence/blob/master/contrib/README.md#runner-plugin) | ||
* Reactive Sequences (via [`react(..)` plugin](https://github.com/getify/asynquence/blob/master/contrib/README.md#react-plugin)) inspired by [RxJS's Reactive Observables](http://rxjs.codeplex.com/) | ||
* [Reactive Sequences](http://jsbin.com/rozipaki/1) (via [`react(..)` plugin](https://github.com/getify/asynquence/blob/master/contrib/README.md#react-plugin)) inspired by [RxJS's Reactive Observables](http://rxjs.codeplex.com/) | ||
* API [Usage Examples](#usage-examples) | ||
@@ -155,2 +155,6 @@ | ||
#### Static Methods | ||
`ASQ.failed(..)` produces a sequence which is already in the failed state. If you pass messages along to `failed(..)`, they will be the error messages for the sequence. | ||
`ASQ.messages(..)` wraps a set of values as a ASQ-branded array, making it easier to pass multiple messages at once, and also to make it easier to distinguish a normal array (a value) from a value-messages container array, using `ASQ.isMessageWrapper(..)`. | ||
@@ -157,0 +161,0 @@ |
@@ -476,7 +476,5 @@ (function(name,context,dependency,definition){ | ||
ASQ() | ||
ASQ | ||
.failed("Hello") | ||
.then(function(done){ | ||
done.fail("Hello"); | ||
}) | ||
.then(function(done){ | ||
clearTimeout(timeout); | ||
@@ -483,0 +481,0 @@ var args = ARRAY_SLICE.call(arguments); |
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
86949
2168
498