forked from kriskowal/q
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq-0.2.0.min.js
6 lines (6 loc) · 2.96 KB
/
q-0.2.0.min.js
1
2
3
4
5
6
(function(d,h){function p(a){return a}function q(){var a=[],b,c=m(i.prototype);c.emit=function(){var e=Array.prototype.slice.call(arguments);a?a.push(e):n.apply(h,[b].concat(e))};c.valueOf=function(){if(a)return c;return b.valueOf()};var f=function(e){var j;if(a){b=k(e);e=0;for(j=a.length;e<j;++e)n.apply(h,[b].concat(a[e]));a=h}};return{promise:r(c),resolve:f,reject:function(e){f(g(e))}}}function i(a,b,c){if(b===h)b=function(e){return g("Promise does not support operation: "+e)};var f=m(i.prototype);
f.emit=function(e,j){j=j||p;var s=Array.prototype.slice.call(arguments,2);s=a[e]?a[e].apply(a,s):b.apply(a,arguments);return j(s)};if(c)f.valueOf=c;return r(f)}function t(a){return a instanceof i}function v(a){if(a===h||a===null)return true;return!w(a)&&!t(a.valueOf())}function w(a){if(a===h||a===null)return false;return a.valueOf()instanceof g}function g(a){return i({when:function(b){return b?b(a):g(a)}},function(b,c){var f=g(a);return c?c(f):f},function(){var b=m(g.prototype);b.reason=a;return b})}
function k(a){if(t(a))return a;return i({when:function(){return a},get:function(b){return a[b]},put:function(b,c){a[b]=c},"delete":function(b){delete a[b]},post:function(b){var c=Array.prototype.slice.call(arguments,1);return a[b].apply(a,c)}},h,function(){return a})}function x(a,b,c){var f=q(),e=false;n(k(a),"when",function(j){if(!e){e=true;f.resolve(k(j).emit("when",b,c))}},function(j){if(!e){e=true;f.resolve(c?c(j):g(j))}});return f.promise}function l(a){return function(b){var c=Array.prototype.slice.call(arguments,
1);return u.apply(h,[b,a].concat(c))}}function u(a,b){var c=q(),f=Array.prototype.slice.call(arguments,2);n.apply(h,[k(a),b,c.resolve].concat(f));return c.promise}function n(a){var b=Array.prototype.slice.call(arguments,1);o(function(){try{a.emit.apply(a,b)}catch(c){y(c.stack||c)}})}var o;try{o=require("event-queue").enqueue}catch(z){o=function(a){setTimeout(a,0)}}var y;y=typeof console!=="undefined"?function(a){console.log(a)}:typeof require!=="undefined"?require("system").print:function(){};var r=
Object.freeze||p,m=Object.create||function(a){var b=function(){};b.prototype=a;return new b};d.enqueue=o;d.defer=q;d.Promise=i;i.prototype.toSource=function(){return this.toString()};i.prototype.toString=function(){return"[object Promise]"};r(i.prototype);d.isPromise=t;d.isResolved=v;d.isRejected=w;d.reject=g;g.prototype=m(i.prototype);g.prototype.constructor=g;d.ref=k;d.def=function(a){return i({isDef:function(){}},function(b){var c=Array.prototype.slice.call(arguments,2);return u.apply(h,[a,b].concat(c))},
function(){return{toString:function(){return"[object Promise def]"}}})};d.when=x;d.asap=function(a,b,c){b=b||p;return v(a)?b(a.valueOf()).valueOf():x(a,b,c)};d.Method=l;d.send=u;d.get=l("get");d.put=l("put");d.del=l("del");d.post=l("post");d.defined=function(a){return d.when(a,function(b){if(b===h||b===null)return g("Resolved undefined value: "+b);return b})};d.error=function(a){a instanceof Error||(a=Error(a));throw a;}})(typeof exports!=="undefined"?exports:this["/q"]={});