Comparing version 0.6.0 to 0.7.0
{ | ||
"name": "q", | ||
"description": "A library for promises (CommonJS/Promises/A,B,D)", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"homepage": "http://github.com/kriskowal/q/", | ||
@@ -6,0 +6,0 @@ "author": "Kris Kowal <kris@cixar.com> (http://github.com/kriskowal/)", |
329
q.js
@@ -42,6 +42,6 @@ // vim:ts=4:sts=4:sw=4: | ||
var enqueue; | ||
var nextTick; | ||
try { | ||
// Narwhal, Node (with a package, wraps process.nextTick) | ||
enqueue = serverSideRequire("event-queue").enqueue; | ||
nextTick = serverSideRequire("event-queue").enqueue; | ||
} catch (e) { | ||
@@ -53,4 +53,12 @@ // browsers | ||
var channel = new MessageChannel(); | ||
enqueue = function (task) { | ||
channel.port1.onmessage = task; | ||
// linked list of tasks (single, with head node) | ||
var head = {}, tail = head; | ||
channel.port1.onmessage = function () { | ||
var next = head.next; | ||
var task = next.task; | ||
head = next; | ||
task(); | ||
}; | ||
nextTick = function (task) { | ||
tail = tail.next = {task: task}; | ||
channel.port2.postMessage(); | ||
@@ -60,3 +68,3 @@ }; | ||
// old browsers | ||
enqueue = function (task) { | ||
nextTick = function (task) { | ||
setTimeout(task, 0); | ||
@@ -68,31 +76,45 @@ }; | ||
// useful for an identity stub and default resolvers | ||
function identity (x) {return x} | ||
function identity (x) {return x;} | ||
// ES5 shims | ||
var freeze = Object.freeze || identity; | ||
var create = Object.create || function create(prototype) { | ||
var Type = function () {}; | ||
Type.prototype = prototype; | ||
return new Type(); | ||
} | ||
var keys = Object.keys || function (object) { | ||
var keys = []; | ||
for (var key in object) | ||
keys.push(key); | ||
return keys; | ||
}; | ||
var reduce = Array.prototype.reduce || function (callback, basis) { | ||
for (var i = 0, ii = this.length; i < ii; i++) { | ||
basis = callback(basis, this[i], i); | ||
} | ||
return basis; | ||
}; | ||
// Spidermonkey Shims | ||
// shims | ||
var freeze = | ||
Object.freeze = | ||
Object.freeze || identity; | ||
var create = | ||
Object.create = | ||
Object.create || function (prototype) { | ||
var Type = function () {}; | ||
Type.prototype = prototype; | ||
return new Type(); | ||
}; | ||
var keys = | ||
Object.keys = | ||
Object.keys || function (object) { | ||
var keys = []; | ||
for (var key in object) | ||
keys.push(key); | ||
return keys; | ||
}; | ||
var reduce = | ||
Array.prototype.reduce = | ||
Array.prototype.reduce || function (callback, basis) { | ||
for (var i = 0, ii = this.length; i < ii; i++) { | ||
basis = callback(basis, this[i], i); | ||
} | ||
return basis; | ||
}; | ||
var isStopIteration = function (exception) { | ||
return Object.prototype.toString.call(exception) | ||
=== "[object StopIteration]"; | ||
} | ||
}; | ||
// Abbreviations for performance and minification | ||
var slice = Array.prototype.slice; | ||
var nil = null; | ||
var print = typeof console === "undefined" ? identity : function (message) { | ||
console.log(message); | ||
var valueOf = function (value) { | ||
if (value === undefined || value === nil) { | ||
return value; | ||
} else { | ||
return value.valueOf(); | ||
} | ||
}; | ||
@@ -104,3 +126,4 @@ | ||
*/ | ||
exports.enqueue = enqueue; | ||
exports.enqueue = // XXX enqueue deprecated | ||
exports.nextTick = nextTick; | ||
@@ -130,7 +153,9 @@ /** | ||
promise.promiseSend = function () { | ||
var args = Array.prototype.slice.call(arguments); | ||
var args = slice.call(arguments); | ||
if (pending) { | ||
pending.push(args); | ||
} else { | ||
forward.apply(undefined, [value].concat(args)); | ||
nextTick(function () { | ||
value.promiseSend.apply(value, args); | ||
}); | ||
} | ||
@@ -142,3 +167,3 @@ }; | ||
return promise; | ||
return valueOf(value); | ||
return value.valueOf(); | ||
}; | ||
@@ -151,5 +176,7 @@ | ||
value = ref(resolvedValue); | ||
for (i = 0, ii = pending.length; i < ii; ++i) { | ||
forward.apply(undefined, [value].concat(pending[i])); | ||
} | ||
reduce.call(pending, function (undefined, pending) { | ||
nextTick(function () { | ||
value.promiseSend.apply(value, pending); | ||
}); | ||
}, undefined); | ||
pending = undefined; | ||
@@ -191,10 +218,14 @@ return value; | ||
promise.promiseSend = function (op, resolved /* ...args */) { | ||
var args = Array.prototype.slice.call(arguments, 2); | ||
var args = slice.call(arguments, 2); | ||
var result; | ||
if (descriptor[op]) | ||
result = descriptor[op].apply(descriptor, args); | ||
else | ||
result = fallback.apply(descriptor, [op].concat(args)); | ||
resolved = resolved || identity; | ||
return resolved(result); | ||
try { | ||
if (descriptor[op]) { | ||
result = descriptor[op].apply(descriptor, args); | ||
} else { | ||
result = fallback.apply(descriptor, [op].concat(args)); | ||
} | ||
} catch (exception) { | ||
result = reject(exception); | ||
} | ||
return (resolved || identity)(result); | ||
}; | ||
@@ -216,3 +247,3 @@ | ||
[ | ||
"when", | ||
"when", "send", | ||
"get", "put", "del", | ||
@@ -224,3 +255,4 @@ "post", "invoke", | ||
"fail", "fin", "spy", // XXX spy deprecated | ||
"report", "end" | ||
"view", "viewInfo", | ||
"end" | ||
], | ||
@@ -231,3 +263,3 @@ function (prev, name) { | ||
exports, | ||
[this].concat(Array.prototype.slice.call(arguments)) | ||
[this].concat(slice.call(arguments)) | ||
); | ||
@@ -263,3 +295,3 @@ }; | ||
function isResolved(object) { | ||
return !isPromise(valueOf(object.valueOf())); | ||
return !isPromise(valueOf(object)); | ||
}; | ||
@@ -282,3 +314,3 @@ | ||
object = valueOf(object); | ||
if (object === undefined || object === null) | ||
if (object === undefined || object === nil) | ||
return false; | ||
@@ -329,3 +361,3 @@ return !!object.promiseRejected; | ||
return when(object, function (value) { | ||
return ref(value).promiseSend.apply(null, arguments); | ||
return ref(value).promiseSend.apply(undefined, arguments); | ||
}); | ||
@@ -344,31 +376,31 @@ } else { | ||
"get": function (name) { | ||
if (object === undefined || object === null) | ||
return reject("Cannot access property " + name + " of " + object); | ||
return object[name]; | ||
}, | ||
"put": function (name, value) { | ||
if (object === undefined || object === null) | ||
return reject("Cannot set property " + name + " of " + object + " to " + value); | ||
return object[name] = value; | ||
}, | ||
"del": function (name) { | ||
if (object === undefined || object === null) | ||
return reject("Cannot delete property " + name + " of " + object); | ||
return delete object[name]; | ||
}, | ||
"post": function (name, value) { | ||
if (object === undefined || object === null) | ||
return reject("" + object + " has no methods"); | ||
var method = object[name]; | ||
if (!method) | ||
return reject("No such method " + name + " on object " + object); | ||
if (!method.apply) | ||
return reject("Property " + name + " on object " + object + " is not a method"); | ||
return object[name].apply(object, value); | ||
}, | ||
"apply": function (self, args) { | ||
if (!object || typeof object.apply !== "function") | ||
return reject("" + object + " is not a function"); | ||
return object.apply(self, args); | ||
}, | ||
"viewInfo": function () { | ||
var on = object; | ||
var properties = {}; | ||
while (on) { | ||
Object.getOwnPropertyNames(on).forEach(function (name) { | ||
if (!properties[name]) | ||
properties[name] = typeof on[name]; | ||
}); | ||
on = Object.getPrototypeOf(on); | ||
} | ||
return { | ||
"type": typeof object, | ||
"properties": properties | ||
} | ||
}, | ||
"keys": function () { | ||
@@ -397,9 +429,50 @@ return keys(object); | ||
}, function fallback(op) { | ||
var args = Array.prototype.slice.call(arguments); | ||
var args = slice.call(arguments); | ||
return send.apply(undefined, [object].concat(args)); | ||
}, function valueOf() { | ||
return object.valueOf(); | ||
}, function () { | ||
return valueOf(object); | ||
}); | ||
} | ||
exports.viewInfo = viewInfo; | ||
function viewInfo(object, info) { | ||
object = ref(object); | ||
if (info) { | ||
return Promise({ | ||
"viewInfo": function () { | ||
return info; | ||
} | ||
}, function fallback(op) { | ||
var args = slice.call(arguments); | ||
return send.apply(undefined, [object].concat(args)); | ||
}, function () { | ||
return valueOf(object); | ||
}); | ||
} else { | ||
return send(object, "viewInfo") | ||
} | ||
} | ||
exports.view = function (object) { | ||
return viewInfo(object).when(function (info) { | ||
var view; | ||
if (info.type === "function") { | ||
view = function () { | ||
return apply(object, undefined, arguments); | ||
}; | ||
} else { | ||
view = {}; | ||
} | ||
var properties = info.properties || {}; | ||
Object.keys(properties).forEach(function (name) { | ||
if (properties[name] === "function") { | ||
view[name] = function () { | ||
return post(object, name, arguments); | ||
}; | ||
} | ||
}); | ||
return ref(view); | ||
}); | ||
}; | ||
/** | ||
@@ -442,13 +515,19 @@ * Registers an observer on a promise. | ||
forward(ref(value), "when", function (value) { | ||
if (done) | ||
return; | ||
done = true; | ||
deferred.resolve(ref(value).promiseSend("when", _fulfilled, _rejected)); | ||
}, function (reason) { | ||
if (done) | ||
return; | ||
done = true; | ||
deferred.resolve(_rejected(reason)); | ||
nextTick(function () { | ||
ref(value).promiseSend("when", function (value) { | ||
if (done) | ||
return; | ||
done = true; | ||
deferred.resolve( | ||
ref(value) | ||
.promiseSend("when", _fulfilled, _rejected) | ||
); | ||
}, function (reason) { | ||
if (done) | ||
return; | ||
done = true; | ||
deferred.resolve(_rejected(reason)); | ||
}); | ||
}); | ||
return deferred.promise; | ||
@@ -458,45 +537,2 @@ } | ||
/** | ||
* Like "when", but attempts to return a fulfilled value in | ||
* the same turn. If the given value is fulfilled and the | ||
* value returned by the fulfilled callback is fulfilled, | ||
* asap returns the latter value in the same turn. | ||
* Otherwise, it returns a promise that will be resolved in | ||
* a future turn. | ||
* | ||
* This method is an experiment in providing an API that can | ||
* unify synchronous and asynchronous API's. An API that | ||
* uses "asap" guarantees that, if it is provided fully | ||
* resolved values, it will produce fully resolved values or | ||
* throw exceptions, but if it is provided asynchronous | ||
* promises, it will produce asynchronous promises. | ||
* | ||
* /!\ WARNING: this method is experimental and likely to be | ||
* removed on the grounds that it probably will result in | ||
* composition hazards. | ||
*/ | ||
exports.asap = function (value, fulfilled, rejected) { | ||
fulfilled = fulfilled || identity; | ||
if (isFulfilled(value)) { | ||
return valueOf(fulfilled(valueOf(value))) | ||
} else if (isRejected(value)) { | ||
var reason = value.valueOf().reason; | ||
if (rejected) { | ||
return rejected(reason); | ||
} else { | ||
throw reason; | ||
} | ||
} else { | ||
return when(value, fulfilled, rejected); | ||
} | ||
}; | ||
var valueOf = function (value) { | ||
if (value === undefined || value === null) { | ||
return value; | ||
} else { | ||
return value.valueOf(); | ||
} | ||
}; | ||
/** | ||
* The async function is a decorator for generator functions, turning | ||
@@ -568,3 +604,3 @@ * them into asynchronous generators. This presently only works in | ||
return function (object) { | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
var args = slice.call(arguments, 1); | ||
return send.apply(undefined, [object, op].concat(args)); | ||
@@ -584,8 +620,10 @@ }; | ||
var deferred = defer(); | ||
var args = Array.prototype.slice.call(arguments, 2); | ||
forward.apply(undefined, [ | ||
ref(object), | ||
op, | ||
deferred.resolve | ||
].concat(args)); | ||
var args = slice.call(arguments, 2); | ||
object = ref(object); | ||
nextTick(function () { | ||
object.promiseSend.apply( | ||
object, | ||
[op, deferred.resolve].concat(args) | ||
); | ||
}); | ||
return deferred.promise; | ||
@@ -641,3 +679,3 @@ } | ||
exports.invoke = function (value, name) { | ||
var args = Array.prototype.slice.call(arguments, 2); | ||
var args = slice.call(arguments, 2); | ||
return post(value, name, args); | ||
@@ -661,3 +699,3 @@ }; | ||
exports.call = function (value, context) { | ||
var args = Array.prototype.slice.call(arguments, 2); | ||
var args = slice.call(arguments, 2); | ||
return apply(value, context, args); | ||
@@ -704,3 +742,3 @@ }; | ||
exports.join = function () { | ||
var args = Array.prototype.slice.call(arguments); | ||
var args = slice.call(arguments); | ||
var callback = args.pop(); | ||
@@ -725,7 +763,7 @@ return all(args).then(function (args) { | ||
return when(promise, function (value) { | ||
return when(callback(undefined, value), function () { | ||
return when(callback(), function () { | ||
return value; | ||
}); | ||
}, function (reason) { | ||
return when(callback(reason), function () { | ||
return when(callback(), function () { | ||
return reject(reason); | ||
@@ -737,17 +775,2 @@ }); | ||
/** | ||
*/ | ||
exports.report = report; | ||
function report(promise, message) { | ||
var error = new Error(message || "REPORT"); | ||
return spy(promise, function (value, reason) { | ||
print(error && error.stack || error); | ||
if (reason) { | ||
print(reason && reason.stack || reason); | ||
} else { | ||
print(value); | ||
} | ||
}); | ||
} | ||
/** | ||
* Terminates a chain of promises, forcing rejections to be | ||
@@ -761,3 +784,3 @@ * thrown as exceptions. | ||
// does not catch it and turn it into a rejection. | ||
enqueue(function () { | ||
nextTick(function () { | ||
throw error; | ||
@@ -769,12 +792,2 @@ }); | ||
/* | ||
* Enqueues a promise operation for a future turn. | ||
*/ | ||
function forward(promise /* ... */) { | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
enqueue(function () { | ||
promise.promiseSend.apply(promise, args); | ||
}); | ||
} | ||
/* | ||
* In module systems that support ``module.exports`` assignment or exports | ||
@@ -781,0 +794,0 @@ * return, allow the ``ref`` function to be used as the ``Q`` constructor |
22
q.min.js
@@ -1,11 +0,11 @@ | ||
(function(n,c){typeof define==="function"?define(function(c,e,k){n(c,e,k)}):typeof exports==="object"?n(require,exports,module):Q=n(c,{},{})})(function(n,c,B,e){function k(a){return a}function o(){var a=[],b,d=p(g.prototype);d.promiseSend=function(){var d=Array.prototype.slice.call(arguments);a?a.push(d):q.apply(e,[b].concat(d))};d.valueOf=function(){if(a)return d;return l(b)};var c=function(d){var c;if(a){b=i(d);d=0;for(c=a.length;d<c;++d)q.apply(e,[b].concat(a[d]));a=e;return b}};return{promise:s(d), | ||
resolve:c,reject:function(a){return c(f(a))}}}function g(a,b,d){b===e&&(b=function(a){return f("Promise does not support operation: "+a)});var c=p(g.prototype);c.promiseSend=function(d,c){var e=Array.prototype.slice.call(arguments,2),e=a[d]?a[d].apply(a,e):b.apply(a,[d].concat(e)),c=c||k;return c(e)};if(d)c.valueOf=d;return s(c)}function r(a){return a&&typeof a.promiseSend==="function"}function x(a){return!r(l(a))&&!t(a)}function t(a){a=l(a);if(a===e||a===null)return!1;return!!a.promiseRejected}function f(a){return g({when:function(b){return b? | ||
b(a):f(a)}},function(){return f(a)},function(){var b=p(f.prototype);b.promiseRejected=!0;b.reason=a;return b})}function i(a){if(r(a))return a;if(a&&typeof a.then==="function")return g({},function(b){return b!=="when"?h(a,function(a){return i(a).promiseSend.apply(null,arguments)}):(b=o(),a.then(b.resolve,b.reject),b.promise)});return g({when:function(){return a},get:function(b){if(a===e||a===null)return f("Cannot access property "+b+" of "+a);return a[b]},put:function(b,d){if(a===e||a===null)return f("Cannot set property "+ | ||
b+" of "+a+" to "+d);return a[b]=d},del:function(b){if(a===e||a===null)return f("Cannot delete property "+b+" of "+a);return delete a[b]},post:function(b,d){if(a===e||a===null)return f(""+a+" has no methods");var c=a[b];if(!c)return f("No such method "+b+" on object "+a);if(!c.apply)return f("Property "+b+" on object "+a+" is not a method");return a[b].apply(a,d)},apply:function(b,d){if(!a||typeof a.apply!=="function")return f(""+a+" is not a function");return a.apply(b,d)},keys:function(){return C(a)}}, | ||
e,function(){return a})}function h(a,b,d){function c(a){try{return b?b(a):a}catch(d){return f(d)}}function e(a){try{return d?d(a):f(a)}catch(b){return f(b)}}var g=o(),h=!1;q(i(a),"when",function(a){h||(h=!0,g.resolve(i(a).promiseSend("when",c,e)))},function(a){h||(h=!0,g.resolve(e(a)))});return g.promise}function j(a){return function(b){var d=Array.prototype.slice.call(arguments,1);return u.apply(e,[b,a].concat(d))}}function u(a,b){var d=o(),c=Array.prototype.slice.call(arguments,2);q.apply(e,[i(a), | ||
b,d.resolve].concat(c));return d.promise}function v(a){return h(a,function(a){var d=a.length,c=[];if(d===0)return i(c);var f=o();y.call(a,function(a,b,e){h(b,function(a){c[e]=a;--d===0&&f.resolve(c)},f.reject)},e);return f.promise})}function q(a){var b=Array.prototype.slice.call(arguments,1);m(function(){a.promiseSend.apply(a,b)})}var m;try{m=n("event-queue").enqueue}catch(F){if(typeof MessageChannel!=="undefined"){var z=new MessageChannel;m=function(a){z.port1.onmessage=a;z.port2.postMessage()}}else m= | ||
function(a){setTimeout(a,0)}}var s=Object.freeze||k,p=Object.create||function(a){var b=function(){};b.prototype=a;return new b},C=Object.keys||function(a){var b=[],d;for(d in a)b.push(d);return b},y=Array.prototype.reduce||function(a,b){for(var d=0,c=this.length;d<c;d++)b=a(b,this[d],d);return b},w=typeof console==="undefined"?k:function(a){console.log(a)};c.enqueue=m;c.defer=o;c.makePromise=g;g.prototype.then=function(a,b){return h(this,a,b)};y.call(["when","get","put","del","post","invoke","keys", | ||
"apply","call","all","wait","join","fail","fin","spy","report","end"],function(a,b){g.prototype[b]=function(){return c[b].apply(c,[this].concat(Array.prototype.slice.call(arguments)))}},e);g.prototype.toSource=function(){return this.toString()};g.prototype.toString=function(){return"[object Promise]"};s(g.prototype);c.isPromise=r;c.isResolved=function(a){return!r(l(a.valueOf()))};c.isFulfilled=x;c.isRejected=t;c.reject=f;f.prototype=p(g.prototype,{constructor:{value:f}});c.ref=i;c.master=c.def=function(a){return g({isDef:function(){}}, | ||
function(){var b=Array.prototype.slice.call(arguments);return u.apply(e,[a].concat(b))},function(){return a.valueOf()})};c.when=h;c.asap=function(a,b,d){b=b||k;if(x(a))return l(b(l(a)));else if(t(a))if(a=a.valueOf().reason,d)return d(a);else throw a;else return h(a,b,d)};var l=function(a){return a===e||a===null?a:a.valueOf()};c.async=function(a){return function(){var b=function(a,b){var g;try{g=d[a](b)}catch(i){return Object.prototype.toString.call(i)==="[object StopIteration]"?i.value:f(i)}return h(g, | ||
c,e)},d=a.apply(this,arguments),c=b.bind(b,"send"),e=b.bind(b,"throw");return c()}};c.Method=j;c.send=u;c.get=j("get");c.put=j("put");c.del=j("del");var D=c.post=j("post");c.invoke=function(a,b){var c=Array.prototype.slice.call(arguments,2);return D(a,b,c)};var E=c.apply=j("apply");c.call=function(a,b){var c=Array.prototype.slice.call(arguments,2);return E(a,b,c)};c.keys=j("keys");c.all=v;c.wait=function(){return v(arguments).get(0)};c.join=function(){var a=Array.prototype.slice.call(arguments),b= | ||
a.pop();return v(a).then(function(a){return b.apply(e,a)})};c.fail=function(a,b){return h(a,e,b)};c.spy=c.fin=function(a,b){return h(a,function(a){return h(b(e,a),function(){return a})},function(a){return h(b(a),function(){return f(a)})})};c.report=function(a,b){var c=Error(b||"REPORT");return spy(a,function(a,b){w(c&&c.stack||c);b?w(b&&b.stack||b):w(a)})};c.end=function(a){h(a,e,function(a){m(function(){throw a;})})};for(var A in c)i[A]=c[A];return B.exports=i}); | ||
(function(n,c){typeof define==="function"?define(function(c,e,o){n(c,e,o)}):typeof exports==="object"?n(require,exports,module):Q=n(c,{},{})})(function(n,c,H,e){function o(a){return a}function p(){var a=[],b,d=r(f.prototype);d.promiseSend=function(){var d=j.call(arguments);a?a.push(d):k(function(){b.promiseSend.apply(b,d)})};d.valueOf=function(){if(a)return d;return m(b)};var c=function(d){if(a)return b=h(d),t.call(a,function(a,d){k(function(){b.promiseSend.apply(b,d)})},e),a=e,b};return{promise:u(d), | ||
resolve:c,reject:function(a){return c(i(a))}}}function f(a,b,d){b===e&&(b=function(a){return i("Promise does not support operation: "+a)});var c=r(f.prototype);c.promiseSend=function(d,c){var y=j.call(arguments,2),e;try{e=a[d]?a[d].apply(a,y):b.apply(a,[d].concat(y)),c=c||o}catch(f){e=i(f)}return c(e)};if(d)c.valueOf=d;return u(c)}function s(a){return a&&typeof a.promiseSend==="function"}function z(a){return!s(m(a))&&!v(a)}function v(a){a=m(a);if(a===e||a===A)return!1;return!!a.promiseRejected}function i(a){return f({when:function(b){return b? | ||
b(a):i(a)}},function(){return i(a)},function(){var b=r(i.prototype);b.promiseRejected=!0;b.reason=a;return b})}function h(a){if(s(a))return a;if(a&&typeof a.then==="function")return f({},function(b){return b!=="when"?g(a,function(a){return h(a).promiseSend.apply(e,arguments)}):(b=p(),a.then(b.resolve,b.reject),b.promise)});return f({when:function(){return a},get:function(b){return a[b]},put:function(b,d){return a[b]=d},del:function(b){return delete a[b]},post:function(b,d){return a[b].apply(a,d)}, | ||
apply:function(b,d){return a.apply(b,d)},viewInfo:function(){for(var b=a,d={};b;)Object.getOwnPropertyNames(b).forEach(function(a){d[a]||(d[a]=typeof b[a])}),b=Object.getPrototypeOf(b);return{type:typeof a,properties:d}},keys:function(){return I(a)}},e,function(){return a})}function B(a,b){a=h(a);return b?f({viewInfo:function(){return b}},function(){var b=j.call(arguments);return q.apply(e,[a].concat(b))},function(){return a.valueOf()}):q(a,"viewInfo")}function g(a,b,d){function c(a){try{return b? | ||
b(a):a}catch(d){return i(d)}}function e(a){try{return d?d(a):i(a)}catch(b){return i(b)}}var f=p(),g=!1;k(function(){h(a).promiseSend("when",function(a){g||(g=!0,f.resolve(h(a).promiseSend("when",c,e)))},function(a){g||(g=!0,f.resolve(e(a)))})});return f.promise}function l(a){return function(b){var d=j.call(arguments,1);return q.apply(e,[b,a].concat(d))}}function q(a,b){var d=p(),c=j.call(arguments,2),a=h(a);k(function(){a.promiseSend.apply(a,[b,d.resolve].concat(c))});return d.promise}function w(a){return g(a, | ||
function(a){var d=a.length,c=[];if(d===0)return h(c);var f=p();t.call(a,function(a,b,e){g(b,function(a){c[e]=a;--d===0&&f.resolve(c)},f.reject)},e);return f.promise})}var k;try{k=n("event-queue").enqueue}catch(J){if(typeof MessageChannel!=="undefined"){var C=new MessageChannel,x={},D=x;C.port1.onmessage=function(){var a=x.next,b=a.task;x=a;b()};k=function(a){D=D.next={task:a};C.port2.postMessage()}}else k=function(a){setTimeout(a,0)}}var u=Object.freeze=Object.freeze||o,r=Object.create=Object.create|| | ||
function(a){var b=function(){};b.prototype=a;return new b},I=Object.keys=Object.keys||function(a){var b=[],d;for(d in a)b.push(d);return b},t=Array.prototype.reduce=Array.prototype.reduce||function(a,b){for(var d=0,c=this.length;d<c;d++)b=a(b,this[d],d);return b},j=Array.prototype.slice,A=null;c.enqueue=k;c.defer=p;c.makePromise=f;f.prototype.then=function(a,b){return g(this,a,b)};t.call(["when","send","get","put","del","post","invoke","keys","apply","call","all","wait","join","fail","fin","spy", | ||
"view","viewInfo","end"],function(a,b){f.prototype[b]=function(){return c[b].apply(c,[this].concat(j.call(arguments)))}},e);f.prototype.toSource=function(){return this.toString()};f.prototype.toString=function(){return"[object Promise]"};u(f.prototype);c.isPromise=s;c.isResolved=function(a){return!s(m(a.valueOf()))};c.isFulfilled=z;c.isRejected=v;c.reject=i;i.prototype=r(f.prototype,{constructor:{value:i}});c.ref=h;c.master=c.def=function(a){return f({isDef:function(){}},function(){var b=j.call(arguments); | ||
return q.apply(e,[a].concat(b))},function(){return a.valueOf()})};c.viewInfo=B;c.view=function(a){return B(a).when(function(b){var d;d=b.type==="function"?function(){return E(a,e,arguments)}:{};var c=b.properties||{};Object.keys(c).forEach(function(b){c[b]==="function"&&(d[b]=function(){return F(a,b,arguments)})});return h(d)})};c.when=g;c.asap=function(a,b,d){b=b||o;if(z(a))return m(b(m(a)));else if(v(a))if(a=a.valueOf().reason,d)return d(a);else throw a;else return g(a,b,d)};var m=function(a){return a=== | ||
e||a===A?a:a.valueOf()};c.async=function(a){return function(){var b=function(a,b){var f;try{f=d[a](b)}catch(h){return Object.prototype.toString.call(h)==="[object StopIteration]"?h.value:i(h)}return g(f,c,e)},d=a.apply(this,arguments),c=b.bind(b,"send"),e=b.bind(b,"throw");return c()}};c.Method=l;c.send=q;c.get=l("get");c.put=l("put");c.del=l("del");var F=c.post=l("post");c.invoke=function(a,b){var d=j.call(arguments,2);return F(a,b,d)};var E=c.apply=l("apply");c.call=function(a,b){var d=j.call(arguments, | ||
2);return E(a,b,d)};c.keys=l("keys");c.all=w;c.wait=function(){return w(arguments).get(0)};c.join=function(){var a=j.call(arguments),b=a.pop();return w(a).then(function(a){return b.apply(e,a)})};c.fail=function(a,b){return g(a,e,b)};c.spy=c.fin=function(a,b){return g(a,function(a){return g(b(),function(){return a})},function(a){return g(b(),function(){return i(a)})})};c.end=function(a){g(a,e,function(a){k(function(){throw a;})})};for(var G in c)h[G]=c[G];return H.exports=h}); |
@@ -689,2 +689,9 @@ | ||
## ``all([...promises])`` | ||
Returns a promise for an array of the fulfillment of each | ||
respective promise, or rejects when the first promise is | ||
rejected. | ||
## ``wait(...objects)`` | ||
@@ -708,2 +715,12 @@ | ||
## ``fin(promise, callback(reason, value))`` | ||
Like a ``finally`` clause, allows you to observe either the | ||
fulfillment or rejection of a callback, but to do so without | ||
modifying the final value. This is useful for collecting | ||
resources regardless of whether a job succeeded, like | ||
closing a database connection, shutting a server down, or | ||
deleting an unneeded key from an object. | ||
## ``report(promise, message_opt)`` | ||
@@ -737,2 +754,11 @@ | ||
## ``async(generatorFunction)`` | ||
This is an experimental tool for converting a generator | ||
function into a deferred function. This has the potential | ||
of reducing nested callbacks in engines that support | ||
``yield``. See ``examples/async-generators/README.md`` for | ||
further information. | ||
Chaining | ||
@@ -752,17 +778,21 @@ -------- | ||
- ``get`` | ||
- ``put`` | ||
- ``del`` | ||
- ``post`` | ||
- ``invoke`` | ||
- ``apply`` | ||
- ``call`` | ||
- ``keys`` | ||
- ``wait`` | ||
- ``join`` | ||
- ``report`` | ||
- ``end`` | ||
- ``.when`` (``.then``) | ||
- ``.get`` | ||
- ``.put`` | ||
- ``.del`` | ||
- ``.post`` | ||
- ``.invoke`` | ||
- ``.apply`` | ||
- ``.call`` | ||
- ``.keys`` | ||
- ``.all`` | ||
- ``.wait`` (``.all().get(0)``) | ||
- ``.join`` (``.all().when(function ([...]) {}))``) | ||
- ``.report`` | ||
- ``.fin`` | ||
- ``.end`` | ||
Copyright 2009-2011 Kristopher Michael Kowal | ||
MIT License (enclosed) | ||
@@ -5,3 +5,2 @@ 'use strict' | ||
exports['test reject'] = require('./reject'); | ||
exports['test asap'] = require('./asap'); | ||
exports['test rosolve & reject'] = require('./resolve-reject') | ||
@@ -8,0 +7,0 @@ exports['test chains of promises'] = require('./promised-chains') |
Sorry, the diff of this file is not supported yet
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
Mixed license
License(Experimental) Package contains multiple licenses.
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
147177
47
2917
2