Comparing version 0.2.3 to 0.2.4
8
p.js
@@ -57,10 +57,6 @@ /*! | ||
function ft( type ) { | ||
return type === "function"; | ||
} | ||
if ( ot(typeof process) && process && process.nextTick ) { | ||
requestTick = process.nextTick; | ||
} else if ( ft(typeof setImmediate) ) { | ||
} else if ( ot(typeof setImmediate) ) { | ||
requestTick = wow ? | ||
@@ -74,3 +70,3 @@ function( cb ) { | ||
} else if ( ft(typeof MessageChannel) ) { | ||
} else if ( ot(typeof MessageChannel) ) { | ||
channel = new MessageChannel(); | ||
@@ -77,0 +73,0 @@ channel.port1.onmessage = onTick; |
@@ -1,1 +0,1 @@ | ||
(function(e){if(typeof module!=="undefined"&&module&&module.exports){module.exports=e()}else if(typeof define==="function"&&define.amd){define(e)}else{P=e()}})(function(){"use strict";var e={f:null,n:null},t=e,n=false,r,i,o=c(typeof window)&&window||c(typeof worker)&&worker,u=c.call,f=c.apply;function a(){while(e.n){e=e.n;var t=e.f;e.f=null;t()}n=false}var s=function(e){t=t.n={f:e,n:null};if(!n){n=true;i(a,0)}};function c(e){return e==="object"||e==="function"}function l(e){return e==="function"}if(c(typeof process)&&process&&process.nextTick){i=process.nextTick}else if(l(typeof setImmediate)){i=o?function(e){o.setImmediate(e)}:function(e){setImmediate(e)}}else if(l(typeof MessageChannel)){r=new MessageChannel;r.port1.onmessage=a;i=function(){r.port2.postMessage(0)}}else{i=setTimeout;if(o&&c(typeof Image)&&Image){(function(){var e=0;var t=function(e){var t=new Image;t.onerror=e;t.src="data:image/png,"};try{t(function(){if(--e===0){i=t}});++e}catch(n){}e&&setTimeout(function(){e=0},0)})()}}function p(e,t){for(var n=0,r=e.length;n<r;++n){if(n in e){t(e[n],n)}}}function v(e){try{if(m.onerror){m.onerror(e)}else{throw e}}catch(t){setTimeout(function(){throw t},0)}}var h=0;var d=1;var _=2;function m(e){return e instanceof I?e:g(new I,e)}function y(e,t,n){if(e._state){return e}e._state=t;e._value=n;if(e._pending.length>0){p(e._pending,s)}e._pending=null;return e}function w(e,t){e._pending.push(t)}function g(e,t){if(e._state){return e}if(t instanceof I){if(t===e){y(e,_,new TypeError("You can't resolve a promise with itself"))}else if(t._state){y(e,t._state,t._value)}else{w(t,function(){y(e,t._state,t._value)})}}else if(t!==Object(t)){y(e,d,t)}else{s(function(){var n=T(e,t);try{var r=t.then;if(typeof r==="function"){u.call(r,t,n.resolve,n.reject)}else{y(e,d,t)}}catch(i){n.reject(i)}})}return e}function T(e,t){var n=false;return{promise:e,resolve:function(r){if(!n){n=true;if(t&&t===r){y(e,d,r)}else{g(e,r)}}},reject:function(t){if(!n){n=true;y(e,_,t)}}}}m.defer=j;function j(){return T(new I)}function I(){this._state=0;this._value=void 0;this._pending=[]}I.prototype.then=function(e,t){var n=typeof e==="function"?e:null;var r=typeof t==="function"?t:null;var i=this;var o=new I;function u(){var e,t=i._state===d?n:r;if(t!==null){try{e=t(i._value)}catch(u){y(o,_,u);return}g(o,e)}else{y(o,i._state,i._value)}}if(i._state===h){w(i,u)}else{s(u)}return o};I.prototype.done=function(e,t){var n=this;if(e||t){n=n.then(e,t)}n.then(null,v)};I.prototype.fail=function(e){return this.then(null,e)};I.prototype.spread=function(e,t){return this.then(e&&function(n){return E(n,[]).then(function(t){return f.call(e,void 0,t)},t)},t)};I.prototype.timeout=function(e,t){var n=this;var r=new I;if(n._state!==h){y(r,n._state,n._value)}else{var i=setTimeout(function(){y(r,_,new Error(t||"Timed out after "+e+" ms"))},e);w(n,function(){clearTimeout(i);y(r,n._state,n._value)})}return r};I.prototype.delay=function(e){var t=this;var n=new I;setTimeout(function(){g(n,t)},e);return n};I.prototype.inspect=function(){switch(this._state){case h:return{state:"pending"};case d:return{state:"fulfilled",value:this._value};case _:return{state:"rejected",reason:this._value};default:throw new TypeError("invalid state")}};function k(e){function t(t){return e(t,[])}function n(e){return m(e).then(t)}n._=e;return n}m.allSettled=k(x);function x(e,t){var n=0;var r=new I;p(e,function(e,i){var o=m(e);if(o._state===h){++n;w(o,function(){t[i]=o.inspect();if(--n===0){y(r,d,t)}})}else{t[i]=o.inspect()}});if(n===0){y(r,d,t)}return r}m.all=k(E);function E(e,t){var n=0;var r=j();p(e,function(e,i){var o=m(e);if(o._state===d){t[i]=o._value}else{++n;o.then(function(e){t[i]=e;if(--n===0){r.resolve(t)}},r.reject)}});if(n===0){r.resolve(t)}return r.promise}m.promised=M;function M(e){function t(t){return f.apply(e,t)}return function(){var e=E(arguments,[]);return E([this,e],[]).then(t)}}m.onerror=null;m.nextTick=function(e){s(function(){try{e()}catch(t){setTimeout(function(){throw t},0)}})};return m}); | ||
(function(e){if(typeof module!=="undefined"&&module&&module.exports){module.exports=e()}else if(typeof define==="function"&&define.amd){define(e)}else{P=e()}})(function(){"use strict";var e={f:null,n:null},t=e,n=false,r,i,o=c(typeof window)&&window||c(typeof worker)&&worker,u=c.call,f=c.apply;function a(){while(e.n){e=e.n;var t=e.f;e.f=null;t()}n=false}var s=function(e){t=t.n={f:e,n:null};if(!n){n=true;i(a,0)}};function c(e){return e==="object"||e==="function"}if(c(typeof process)&&process&&process.nextTick){i=process.nextTick}else if(c(typeof setImmediate)){i=o?function(e){o.setImmediate(e)}:function(e){setImmediate(e)}}else if(c(typeof MessageChannel)){r=new MessageChannel;r.port1.onmessage=a;i=function(){r.port2.postMessage(0)}}else{i=setTimeout;if(o&&c(typeof Image)&&Image){(function(){var e=0;var t=function(e){var t=new Image;t.onerror=e;t.src="data:image/png,"};try{t(function(){if(--e===0){i=t}});++e}catch(n){}e&&setTimeout(function(){e=0},0)})()}}function l(e,t){for(var n=0,r=e.length;n<r;++n){if(n in e){t(e[n],n)}}}function p(e){try{if(_.onerror){_.onerror(e)}else{throw e}}catch(t){setTimeout(function(){throw t},0)}}var v=0;var h=1;var d=2;function _(e){return e instanceof j?e:w(new j,e)}function m(e,t,n){if(e._state){return e}e._state=t;e._value=n;if(e._pending.length>0){l(e._pending,s)}e._pending=null;return e}function y(e,t){e._pending.push(t)}function w(e,t){if(e._state){return e}if(t instanceof j){if(t===e){m(e,d,new TypeError("You can't resolve a promise with itself"))}else if(t._state){m(e,t._state,t._value)}else{y(t,function(){m(e,t._state,t._value)})}}else if(t!==Object(t)){m(e,h,t)}else{s(function(){var n=g(e,t);try{var r=t.then;if(typeof r==="function"){u.call(r,t,n.resolve,n.reject)}else{m(e,h,t)}}catch(i){n.reject(i)}})}return e}function g(e,t){var n=false;return{promise:e,resolve:function(r){if(!n){n=true;if(t&&t===r){m(e,h,r)}else{w(e,r)}}},reject:function(t){if(!n){n=true;m(e,d,t)}}}}_.defer=T;function T(){return g(new j)}function j(){this._state=0;this._value=void 0;this._pending=[]}j.prototype.then=function(e,t){var n=typeof e==="function"?e:null;var r=typeof t==="function"?t:null;var i=this;var o=new j;function u(){var e,t=i._state===h?n:r;if(t!==null){try{e=t(i._value)}catch(u){m(o,d,u);return}w(o,e)}else{m(o,i._state,i._value)}}if(i._state===v){y(i,u)}else{s(u)}return o};j.prototype.done=function(e,t){var n=this;if(e||t){n=n.then(e,t)}n.then(null,p)};j.prototype.fail=function(e){return this.then(null,e)};j.prototype.spread=function(e,t){return this.then(e&&function(n){return x(n,[]).then(function(t){return f.call(e,void 0,t)},t)},t)};j.prototype.timeout=function(e,t){var n=this;var r=new j;if(n._state!==v){m(r,n._state,n._value)}else{var i=setTimeout(function(){m(r,d,new Error(t||"Timed out after "+e+" ms"))},e);y(n,function(){clearTimeout(i);m(r,n._state,n._value)})}return r};j.prototype.delay=function(e){var t=this;var n=new j;setTimeout(function(){w(n,t)},e);return n};j.prototype.inspect=function(){switch(this._state){case v:return{state:"pending"};case h:return{state:"fulfilled",value:this._value};case d:return{state:"rejected",reason:this._value};default:throw new TypeError("invalid state")}};function I(e){function t(t){return e(t,[])}function n(e){return _(e).then(t)}n._=e;return n}_.allSettled=I(k);function k(e,t){var n=0;var r=new j;l(e,function(e,i){var o=_(e);if(o._state===v){++n;y(o,function(){t[i]=o.inspect();if(--n===0){m(r,h,t)}})}else{t[i]=o.inspect()}});if(n===0){m(r,h,t)}return r}_.all=I(x);function x(e,t){var n=0;var r=T();l(e,function(e,i){var o=_(e);if(o._state===h){t[i]=o._value}else{++n;o.then(function(e){t[i]=e;if(--n===0){r.resolve(t)}},r.reject)}});if(n===0){r.resolve(t)}return r.promise}_.promised=E;function E(e){function t(t){return f.apply(e,t)}return function(){var e=x(arguments,[]);return x([this,e],[]).then(t)}}_.onerror=null;_.nextTick=function(e){s(function(){try{e()}catch(t){setTimeout(function(){throw t},0)}})};return _}); |
{ | ||
"name": "p-promise", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "A simple Promises/A+ library.", | ||
@@ -5,0 +5,0 @@ "author": "Robert Katić <robert.katic@gmail.com> (https://github.com/rkatic)", |
@@ -77,7 +77,10 @@ | ||
it("should fulfill with input if not a promise", function() { | ||
it("should fulfill with input if not a promise", function( done ) { | ||
var c = 0; | ||
forEach(VALUES, function( value ) { | ||
var p = P( value ); | ||
p.then(null, function() { | ||
fail(); | ||
++c; | ||
P( value ).then(function() { | ||
if ( --c === 0 ) { | ||
done(); | ||
} | ||
}); | ||
@@ -84,0 +87,0 @@ }); |
31356