asynquence
Advanced tools
Comparing version 0.4.0-b to 0.4.1-a
/*! asynquence | ||
v0.4.0-b (c) Kyle Simpson | ||
v0.4.1-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){g(n)||(n=n.apply(b,d.call(arguments,1))),n.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){"function"!=typeof e||"then"in e||(e=e.apply(b,d.call(arguments,1))),e.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(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}); |
/*! asynquence | ||
v0.4.0-b (c) Kyle Simpson | ||
v0.4.1-a (c) Kyle Simpson | ||
MIT License: http://getify.mit-license.org | ||
@@ -438,2 +438,3 @@ */ | ||
then(function __then__(done){ | ||
var _fn = fn; | ||
// check if this argument is not already an ASQ instance? | ||
@@ -443,6 +444,6 @@ // if not, assume a function to invoke that will return | ||
if (!isSequence(fn)) { | ||
fn = fn.apply(ø,ARRAY_SLICE.call(arguments,1)); | ||
_fn = fn.apply(ø,ARRAY_SLICE.call(arguments,1)); | ||
} | ||
// pipe the ASQ instance into our current sequence | ||
fn.pipe(done); | ||
_fn.pipe(done); | ||
}); | ||
@@ -489,2 +490,3 @@ }); | ||
then(function __then__(done){ | ||
var _pr = pr; | ||
// check if this argument is a non-thenable function, and | ||
@@ -494,6 +496,6 @@ // if so, assume we shold invoke it to return a promise | ||
if (typeof pr === "function" && !("then" in pr)) { | ||
pr = pr.apply(ø,ARRAY_SLICE.call(arguments,1)); | ||
_pr = pr.apply(ø,ARRAY_SLICE.call(arguments,1)); | ||
} | ||
// now, hook up the promise to the sequence | ||
pr.then( | ||
_pr.then( | ||
wrap(done), | ||
@@ -500,0 +502,0 @@ wrap(done.fail) |
@@ -9,7 +9,6 @@ #!/usr/bin/env node | ||
var ASQ = require("./asq.src.js"); | ||
var Q = require("q"); | ||
var tests = require("./tests.js")(doneLogMsg); | ||
tests.Q = Q; // inject Q so the tests can use it | ||
require("native-promise-only"); | ||
var path = require("path"); | ||
var ASQ = require(path.join(__dirname,"asq.src.js")); | ||
var tests = require(path.join(__dirname,"tests.js"))(doneLogMsg); | ||
var fs = require("fs"); | ||
@@ -16,0 +15,0 @@ var child_process = require("child_process"); |
{ | ||
"name": "asynquence", | ||
"version": "0.4.0-b", | ||
"description": "asynquence: async sequences & gates for flow-control", | ||
"version": "0.4.1-a", | ||
"description": "asynquence: promise-style async sequence flow-control", | ||
"main": "./asq.js", | ||
@@ -12,3 +12,3 @@ "scripts": { | ||
"uglify-js": "~2.4.8", | ||
"q": "~0.9.7" | ||
"native-promise-only": "latest" | ||
}, | ||
@@ -15,0 +15,0 @@ "repository": { |
@@ -55,3 +55,3 @@ # asynquence | ||
Whenever a sequence goes into the error state, any error handlers on that sequence (or any sequence that it's been `pipe()`d to -- see [Conveniences](#conveniences) below), has registered with `or(..)` will be fired. Even registering `or(..)` handlers after a sequence is already in the error state will also queue them to be fired (async, on the next event loop turn). | ||
Whenever a sequence goes into the error state, any error handlers on that sequence (or any sequence that it's been `pipe()`d to -- see [Conveniences](#conveniences) below) registered with `or(..)` will be fired. Even registering `or(..)` handlers after a sequence is already in the error state will also queue them to be fired (async, on the next event loop turn). | ||
@@ -58,0 +58,0 @@ Errors can be programmatic failures (see above) or they can be uncaught JS errors such as `ReferenceError` or `TypeError`: |
40
tests.js
@@ -863,11 +863,11 @@ (function(name,context,dependency,definition){ | ||
tests.push(function(testDone){ | ||
var label = "Core Test #20", timeout, Q = tests.Q; | ||
var label = "Core Test #20", timeout; | ||
function Pr(){ | ||
var args = ASQ.messages.apply(ø,arguments); | ||
var def = Q.defer(); | ||
setTimeout(function(){ | ||
def.resolve(args.length > 1 ? args : args[0]); | ||
},10); | ||
return def.promise; | ||
return new Promise(function(resolve){ | ||
setTimeout(function(){ | ||
resolve(args.length > 1 ? args : args[0]); | ||
},10); | ||
}); | ||
} | ||
@@ -877,7 +877,7 @@ | ||
var args = ASQ.messages.apply(ø,arguments); | ||
var def = Q.defer(); | ||
setTimeout(function(){ | ||
def.reject(args.length > 1 ? args : args[0]); | ||
},10); | ||
return def.promise; | ||
return new Promise(function(_,reject){ | ||
setTimeout(function(){ | ||
reject(args.length > 1 ? args : args[0]); | ||
},10); | ||
}); | ||
} | ||
@@ -1171,3 +1171,21 @@ | ||
function seqMessages(msg1,msg2,msg3) { | ||
return ASQ(function(done){ | ||
setTimeout(function(){ | ||
done(msg1,msg2,msg3); | ||
},25); | ||
}); | ||
} | ||
function promiseMessages(msg1,msg2,msg3) { | ||
return new Promise(function(resolve){ | ||
setTimeout(function(){ | ||
resolve(ASQ.messages(msg1,msg2,msg3)); | ||
},25); | ||
}); | ||
} | ||
sq1 = ASQ() | ||
.seq(seqMessages) | ||
.promise(promiseMessages) | ||
.val(function(s1,s2,s3){ | ||
@@ -1174,0 +1192,0 @@ // if any messages received, use them |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
85513
2129
6