-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpromise.min.js
10 lines (10 loc) · 2.69 KB
/
promise.min.js
1
2
3
4
5
6
7
8
9
10
/*
* [promise.coffee](http://github.com/CodeCatalyst/promise.coffee) v1.0.6
* Copyright (c) 2012-2013 [CodeCatalyst, LLC](http://www.codecatalyst.com/).
* Open source under the [MIT License](http://en.wikipedia.org/wiki/MIT_License).
*/
(function(){var m,f,n,k,p,q,h,r,s,l;s=null!=("undefined"!==typeof process&&null!==process?process.nextTick:void 0)?process.nextTick:"undefined"!==typeof setImmediate&&null!==setImmediate?setImmediate:function(a){return setTimeout(a,0)};p=new (function(){return function(){var a,e,b;b=Array(1E4);e=0;a=function(){var a;for(a=0;a<e;)b[a](),b[a]=null,a++;e=0};this.schedule=function(c){b[e++]=c;1===e&&s(a)}}}());q=function(a){return p.schedule(a)};h=function(a){return a&&"function"===typeof a};r=function(a){return a&&
"object"===typeof a};m=function(){function a(a,b){this.onFulfilled=a;this.onRejected=b;this.resolver=new k;this.promise=this.resolver.promise}a.prototype.trigger=function(a,b){switch(a){case "fulfill":this.propagate(b,this.onFulfilled,this.resolver,this.resolver.resolve);break;case "reject":this.propagate(b,this.onRejected,this.resolver,this.resolver.reject)}};a.prototype.propagate=function(a,b,c,d){h(b)?q(function(){try{c.resolve(b(a))}catch(d){c.reject(d)}}):d.call(c,a)};return a}();k=function(){function a(){this.promise=
new n(this);this.consequences=[];this.completed=!1;this.completionValue=this.completionAction=null}a.prototype.then=function(a,b){var c;c=new m(a,b);this.completed?c.trigger(this.completionAction,this.completionValue):this.consequences.push(c);return c.promise};a.prototype.resolve=function(a){var b,c,d,t;if(!this.completed)try{if(a===this.promise)throw new TypeError("A Promise cannot be resolved with itself.");if((r(a)||h(a))&&h(t=a.then)){c=!1;try{d=this,t.call(a,function(a){c||(c=!0,d.resolve(a))},
function(a){c||(c=!0,d.reject(a))})}catch(g){b=g,c||this.reject(b)}}else this.complete("fulfill",a)}catch(f){b=f,this.reject(b)}};a.prototype.reject=function(a){this.completed||this.complete("reject",a)};a.prototype.complete=function(a,b){var c,d,f,g;this.completionAction=a;this.completionValue=b;this.completed=!0;g=this.consequences;d=0;for(f=g.length;d<f;d++)c=g[d],c.trigger(this.completionAction,this.completionValue);this.consequences=null};return a}();n=function(){return function(a){this.then=
function(e,b){return a.then(e,b)}}}();f=function(){function a(){var a;a=new k;this.promise=a.promise;this.resolve=function(b){return a.resolve(b)};this.reject=function(b){return a.reject(b)}}a.resolve=function(e){var b;b=new a;b.resolve(e);return b.promise};a.reject=function(e){var b;b=new a;b.reject(e);return b.promise};return a}();l="undefined"!==typeof exports&&null!==exports?exports:window;l.Deferred=f;l.defer=function(){return new f}}).call(this);