-
Notifications
You must be signed in to change notification settings - Fork 1
/
andthen.min.js
1 lines (1 loc) · 1.33 KB
/
andthen.min.js
1
(function(e){if(typeof exports==="object"){module.exports=e()}else if(typeof define==="function"&&define.amd){define(e)}else{andthen=e()}})(function(){"use strict";var e=function(){function s(t){if(t.length===1&&t[0]&&t[0].then){return t[0]}return{then:function(n){var r=e();process.nextTick(function(){r.resolve(n.apply(null,t))});return r.promise}}}var n=[],r;if(arguments.length!==0){var i=e();i.resolve.apply(i,arguments);return i.promise}return{resolve:function(){if(n){r=s(arguments);if(n.length===0&&r._error){r.then(null,function(e){throw e})}for(var e=0,t=n.length;e<t;e+=1){r.then.apply(r,n[e])}n=undefined}},promise:{then:function(i,s){var o=e();i=i||function(e){return e};s=s||function(e){return t(e)};var u=function(){var e;try{e=i.apply(null,arguments)}catch(n){e=t(n)}o.resolve(e)};var a=function(e){o.resolve(s(e))};if(n){n.push([u,a])}else{process.nextTick(function(){r.then(u,a)})}return o.promise},and:function(t){function s(){if(r&&i){n.resolve.apply(n,r.concat(i))}}function o(t){n.resolve(e.reject(t))}var n=e();var r,i;this.then(function(){r=[].splice.call(arguments,0);s()},o);t.then(function(e){i=[].splice.call(arguments,0);s()},o);return n.promise}}}};var t=function(t){if(t&&t.then&&t._error){return t}return{_error:true,then:function(n,r){var i=e();process.nextTick(function(){i.resolve(r(t))});return i.promise}}};e.reject=t;return e})