asynquence
Advanced tools
Comparing version 0.3.2-a to 0.3.2-b
/*! asynquence | ||
v0.3.2-a (c) Kyle Simpson | ||
v0.3.2-b (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 r(){function n(){clearTimeout(j),j=null,I.length=0,Q.length=0,w.length=0,C.length=0}function e(){return S?l():(j||(j=t(l)),void 0)}function l(){var t,r;if(j=null,S)n();else if(O)for(;Q.length;){t=Q.shift();try{t.apply(m,C)}catch(u){a(u)?C=C.concat(u):(C.push(u),u.stack&&C.push(u.stack)),0===Q.length&&console.error.apply(console,C)}}else if(T&&I.length>0){T=!1,t=I.shift(),r=w.slice(),w.length=0,r.unshift(p());try{t.apply(m,r)}catch(u){a(u)?C=C.concat(u):C.push(u),O=!0,e()}}}function p(){function n(){O||S||T||(T=!0,w.push.apply(w,arguments),C.length=0,e())}return n.fail=function(){O||S||T||(O=!0,w.length=0,C.push.apply(C,arguments),e())},n.abort=function(){O||S||(T=!1,S=!0,w.length=0,C.length=0,e())},n.errfcb=function(e){e?n.fail(e):n.apply(m,g.call(arguments,1))},n}function h(n,e,r){function u(){clearTimeout(y),y=_=q=h=null}function l(){return v?c():(y||(y=t(c)),void 0)}function c(){if(!(O||S||b)){var e=[];y=null,d?(n.fail.apply(m,h),u()):v?(n.abort(),u()):i()&&(b=!0,_.forEach(function(n,t){e.push(q["s"+t])}),n.apply(m,e),u())}}function i(){if(!(O||S||d||v||b||0===_.length)){var n=!0;return _.some(function(e){return null===e?(n=!1,!0):void 0}),n}}function o(){function n(){if(!(O||S||d||v||b||_[e])){var n=f.messages.apply(m,arguments);q["s"+e]=n.length>1?n:n[0],_[e]=!0,l()}}var e=_.length;return n.fail=function(){O||S||d||v||b||_[e]||(d=!0,h=g.call(arguments),l())},n.abort=function(){O||S||d||v||b||(v=!0,c())},n.errfcb=function(e){e?n.fail(e):n.apply(m,g.call(arguments,1))},_[e]=null,n}var s,p,h,y,d=!1,v=!1,b=!1,_=[],q={};e.some(function(n){if(d||v)return!0;s=r.slice(),s.unshift(o());try{n.apply(m,s)}catch(e){return p=e,d=!0,!0}}),p&&(a(p)?n.fail.apply(m,p):n.fail(p))}function y(){return O||S||0===arguments.length?M:(I.push.apply(I,o(arguments,i)),e(),M)}function d(){return S||0===arguments.length?M:(Q.push.apply(Q,arguments),e(),M)}function v(){if(O||S||0===arguments.length)return M;var n=g.call(arguments);return y(function(e){var t=g.call(arguments,1);h(e,n,t)}),M}function b(){return S||0===arguments.length?M:(g.call(arguments).forEach(function(n){y(function(e){n.apply(m,g.call(arguments,1)),e()}).or(n.fail)}),M)}function _(){return O||S||0===arguments.length?M:(g.call(arguments).forEach(function(n){var e;a(n)&&"next"in n&&(n.then(function(){e.apply(m,arguments)}).or(function(){e.fail.apply(m,arguments)}),n=r(function(n){e=n}),e=function(){n=r.apply(m,arguments)},e.fail=function(){var e=g.call(arguments);n=r(function(n){n.fail.apply(m,e)})}),y(function(e){a(n)||(n=n.apply(m,g.call(arguments,1))),n.pipe(e)})}),M)}function q(){return O||S||0===arguments.length?M:(g.call(o(arguments,c)).forEach(function(n){y(function(e){var t=n.apply(m,g.call(arguments,1));a(t)||(t=f.messages(t)),e.apply(m,t)})}),M)}function k(){return O||S||0===arguments.length?M:(g.call(arguments).forEach(function(n){y(function(e){"function"!=typeof n||"then"in n||(n=n.apply(m,g.call(arguments,1))),n.then(e,e.fail)})}),M)}function E(){return O?M:(S=!0,l(),M)}function x(n,e){var t=arguments.length>1;switch(n){case"seq_error":if(!t)return O;O=e;break;case"seq_aborted":if(!t)return S;S=e;break;case"then_ready":if(!t)return T;T=e;break;case"then_queue":return I;case"or_queue":return Q;case"sequence_messages":return w;case"sequence_errors":return C}}function A(){Object.keys(s).forEach(function(n){M[n]=s[n](M,x)})}var j,O=!1,S=!1,T=!0,I=[],Q=[],w=[],C=[],M=u({then:y,or:d,gate:v,pipe:b,seq:_,val:q,promise:k,abort:E});return A(),M.then.apply(m,o(arguments,i)),M}function u(n){return Object.defineProperty(n,h,{enumerable:!1,value:!0}),n}function a(n){return null!=n&&"object"==typeof n&&n[h]}function l(n,e){return g.call(e).slice(1,n+1)}function c(n){return f.messages.apply(m,l(n,arguments))}function i(n){arguments[n+1].apply(m,l(n,arguments))}function o(n,e){var t,r;for(n=g.call(n),t=0;t<n.length;t++)if(Array.isArray(n[t])&&a(n[t]))n[t]=e.bind.apply(e,[null,n[t].length].concat(n[t]));else if("function"!=typeof n[t]){for(r=t+1;r<n.length&&("function"!=typeof n[r]&&!a(n[r]));r++);n.splice(t,r-t,e.bind.apply(e,[null,r-t].concat(n.slice(t,r))))}return n}var f,s={},p=(e||{})[n],g=Array.prototype.slice,h="__ASQ__",m=Object.create(null);return f=r,f.extend=function(n,e){return~["then","or","gate","pipe","seq","val","abort"].indexOf(n)||(s[n]=e),f},f.messages=function(){var n=g.call(arguments);return u(n),n},f.isMessageWrapper=f.isSequence=a,f.noConflict=function(){return e&&(e[n]=p),f},f}); |
/*! asynquence | ||
v0.3.2-a (c) Kyle Simpson | ||
v0.3.2-b (c) Kyle Simpson | ||
MIT License: http://getify.mit-license.org | ||
@@ -4,0 +4,0 @@ */ |
{ | ||
"name": "asynquence", | ||
"version": "0.3.2-a", | ||
"description": "asynquence: async sequences & gates for flow-control", | ||
"main": "./asq.js", | ||
"scripts": { | ||
"test": "./node-tests.js", | ||
"build-core": "./build-core.js" | ||
}, | ||
"devDependencies": { | ||
"uglify-js": "~2.4.8", | ||
"q": "~0.9.7" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/getify/asynquence.git" | ||
}, | ||
"keywords": [ | ||
"async", | ||
"flow-control", | ||
"sequences", | ||
"promise", | ||
"iterator", | ||
"generator" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/getify/asynquence/issues", | ||
"email": "getify@gmail.com" | ||
}, | ||
"homepage": "http://github.com/getify/asynquence", | ||
"author": "Kyle Simpson <getify@gmail.com>", | ||
"license": "MIT" | ||
"name": "asynquence", | ||
"version": "0.3.2-b", | ||
"description": "asynquence: async sequences & gates for flow-control", | ||
"main": "./asq.js", | ||
"scripts": { | ||
"test": "./node-tests.js", | ||
"build-core": "./build-core.js" | ||
}, | ||
"devDependencies": { | ||
"uglify-js": "~2.4.8", | ||
"q": "~0.9.7" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/getify/asynquence.git" | ||
}, | ||
"keywords": [ | ||
"async", | ||
"flow-control", | ||
"sequences", | ||
"promise", | ||
"iterator", | ||
"generator" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/getify/asynquence/issues", | ||
"email": "getify@gmail.com" | ||
}, | ||
"homepage": "http://github.com/getify/asynquence", | ||
"author": "Kyle Simpson <getify@gmail.com>", | ||
"license": "MIT" | ||
} |
@@ -65,7 +65,7 @@ # asynquence | ||
* `errfcb` is a flag on the triggers that are passed into `then(..)` steps and `gate(..)` segments. If you're using methods which expect an "error-first" style (aka, "node-style") callback, `{trigger}.errcb` provides a properly formatted callback for the occasion. | ||
* `errfcb` is a flag on the triggers that are passed into `then(..)` steps and `gate(..)` segments. If you're using methods which expect an "error-first" style (aka, "node-style") callback, `{trigger}.errfcb` provides a properly formatted callback for the occasion. | ||
If the "error-first" callback is then invoked with the first ("error") parameter set, the main sequence is flagged for error as usual. Otherwise, the main sequence proceeds as success. Messages sent to the callback are passed through to the main sequence as success/error as expected. | ||
`ASQ(function(done){ somethingAsync(done.errcb); })` is sugar short-hand for `ASQ(function(done){ somethingAsync(function(err){ if (err) done.fail(err); else done.apply(null,[].slice.call(arguments,1))}); })`. | ||
`ASQ(function(done){ somethingAsync(done.errfcb); })` is sugar short-hand for `ASQ(function(done){ somethingAsync(function(err){ if (err) done.fail(err); else done.apply(null,[].slice.call(arguments,1))}); })`. | ||
@@ -72,0 +72,0 @@ You can also `abort()` a sequence at any time, which will prevent any further actions from occurring on that sequence (all callbacks will be ignored). The call to `abort()` can happen on the sequence API itself, or using the `abort` flag on a completion trigger in any step (see example below). |
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
66773