New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

p-promise

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

p-promise - npm Package Compare versions

Comparing version 0.3.2 to 0.3.4

out.txt

407

p.js

@@ -25,20 +25,25 @@ /*!

var
isNodeJS = ot(typeof process) &&
isNodeJS = ot(typeof process) && process != null &&
({}).toString.call(process) === "[object process]",
hasSetImmediate = ot(typeof setImmediate),
hasSetImmediate = typeof setImmediate === "function",
head = { f: null, n: null }, tail = head,
gMutationObserver =
ot(typeof MutationObserver) && MutationObserver ||
ot(typeof WebKitMutationObserver) && WebKitMutationObserver,
head = new TaskNode(),
tail = head,
flushing = false,
nFreeTaskNodes = 0,
requestFlush =
isNodeJS && requestFlushForNodeJS ||
makeRequestCallFromMutationObserver( flush ) ||
isNodeJS ? requestFlushForNodeJS :
gMutationObserver ? makeRequestCallFromMutationObserver( flush ) :
makeRequestCallFromTimer( flush ),
pendingErrors = [],
requestErrorThrow = makeRequestCallFromTimer( throwFristError ),
requestErrorThrow = makeRequestCallFromTimer( throwFirstError ),
wrapTask,
asapSafeTask,
handleError,

@@ -50,2 +55,12 @@ domain,

tail.next = head;
function TaskNode() {
this.task = null;
this.domain = null;
this.a = null;
this.b = null;
this.next = null;
}
function ot( type ) {

@@ -55,3 +70,3 @@ return type === "object" || type === "function";

function throwFristError() {
function throwFirstError() {
if ( pendingErrors.length ) {

@@ -63,13 +78,66 @@ throw pendingErrors.shift();

function flush() {
while ( head.n ) {
head = head.n;
var f = head.f;
head.f = null;
f.call();
while ( head !== tail ) {
head = head.next;
var task = head.task;
if ( nFreeTaskNodes >= 1024 ) {
tail.next = tail.next.next;
} else {
++nFreeTaskNodes;
}
if ( head.domain ) {
runInDomain( head.domain, task, head.a, head.b, void 0 );
head.domain = null;
} else {
task( head.a, head.b );
}
head.task = null;
head.a = null;
head.b = null;
}
flushing = false;
}
var runLater = function( f ) {
tail = tail.n = { f: f, n: null };
function beforeThrow() {
head.task = null;
head.domain = null;
head.a = null;
head.b = null;
requestFlush();
}
function runInDomain( domain, task, a, b, c ) {
if ( domain._disposed ) {
return;
}
domain.enter();
task( a, b, c );
domain.exit();
}
function queueTask( setDomain, task, a, b ) {
var node = tail.next;
if ( node === head ) {
node = new TaskNode();
tail.next = node;
node.next = head;
} else {
--nFreeTaskNodes;
}
tail = node;
node.task = task;
node.a = a;
node.b = b;
if ( setDomain && isNodeJS ) {
node.domain = process.domain;
}
if ( !flushing ) {

@@ -79,3 +147,3 @@ flushing = true;

}
};
}

@@ -103,13 +171,5 @@ function requestFlushForNodeJS() {

function makeRequestCallFromMutationObserver( callback ) {
var observer =
ot(typeof MutationObserver) ? new MutationObserver( callback ) :
ot(typeof WebKitMutationObserver) ? new WebKitMutationObserver( callback ) :
null;
if ( !observer ) {
return null;
}
var toggle = 1;
var node = document.createTextNode("");
var observer = new gMutationObserver( callback );
observer.observe( node, {characterData: true} );

@@ -137,50 +197,21 @@

if ( isNodeJS ) {
wrapTask = function( task ) {
var d = process.domain;
return function() {
if ( d ) {
if ( d._disposed ) return;
d.enter();
}
try {
task.call();
} catch ( e ) {
requestFlush();
throw e;
}
if ( d ) {
d.exit();
}
};
handleError = function( e ) {
beforeThrow();
throw e;
};
asapSafeTask = function( task ) {
var d = process.domain;
runLater(!d ? task : function() {
if ( !d._disposed ) {
d.enter();
task.call();
d.exit();
}
});
} else {
handleError = function( e ) {
pendingErrors.push( e );
requestErrorThrow();
}
}
} else {
wrapTask = function( task ) {
return function() {
try {
task.call();
function tryCall( toCall, onError ) {
try {
toCall.call();
} catch ( e ) {
pendingErrors.push( e );
requestErrorThrow();
}
};
} catch ( e ) {
onError( e );
}
asapSafeTask = runLater;
}

@@ -190,3 +221,3 @@

function asap( task ) {
runLater( wrapTask(task) );
queueTask( true, tryCall, task, handleError );
}

@@ -223,6 +254,6 @@

x :
Resolve( new Promise(), x );
Resolve( new Promise(), x, false );
}
function Settle( p, state, value, domain ) {
function Settle( p, state, value ) {
if ( p._state ) {

@@ -235,13 +266,9 @@ return p;

if ( domain ) {
p._domain = domain;
} else if ( isNodeJS && state === REJECTED ) {
if ( state === REJECTED && isNodeJS ) {
p._domain = process.domain;
}
if ( p._pending.length ) {
forEach( p._pending, runLater );
if ( p._pending ) {
QueueChildren( p );
}
p._pending = null;

@@ -251,11 +278,19 @@ return p;

function OnSettled( p, f ) {
p._pending.push( f );
}
function Propagate( parent, p ) {
if ( p._state ) {
return p;
}
function Propagate( p, p2 ) {
Settle( p2, p._state, p._value, p._domain );
p._state = parent._state;
p._value = parent._value;
p._domain = parent._domain;
if ( p._pending ) {
QueueChildren( p );
}
return p;
}
function Resolve( p, x ) {
function Resolve( p, x, sync ) {
if ( p._state ) {

@@ -273,5 +308,3 @@ return p;

} else {
OnSettled(x, function() {
Propagate( x, p );
});
Follow( p, x );
}

@@ -282,25 +315,99 @@

} else if ( sync ) {
Assimilate( p, x );
} else {
asapSafeTask(function() {
var r = resolverFor( p );
queueTask( true, Assimilate, p, x );
}
try {
var then = x.then;
return p;
}
if ( typeof then === "function" ) {
call.call( then, x, r.resolve, r.reject );
function Assimilate( p, x ) {
var r, then;
} else {
Settle( p, FULFILLED, x );
}
try {
then = x.then;
} catch ( e ) {
r.reject( e );
}
});
} catch ( e1 ) {
Settle( p, REJECTED, e1 );
return;
}
return p;
if ( typeof then === "function" ) {
r = resolverFor( p );
try {
call.call( then, x, r.resolve, r.reject );
} catch ( e2 ) {
r.reject( e2 );
}
} else {
Settle( p, FULFILLED, x );
}
}
function QueueChildren( p ) {
var pending = p._pending;
p._pending = null;
if ( pending instanceof Promise ) {
queueTask( false, Then, p, pending );
return;
}
for ( var i = 0, l = pending.length; i < l; ++i ) {
queueTask( false, Then, p, pending[i] );
}
}
function Follow( child, p ) {
if ( !p._pending ) {
p._pending = child;
} else if ( p._pending instanceof Promise ) {
p._pending = [ p._pending, child ];
} else {
p._pending.push( child );
}
}
function Then( parent, child ) {
var cb = parent._state === FULFILLED ? child._cb : child._eb;
child._cb = null;
child._eb = null;
if ( !cb ) {
Propagate( parent, child );
return;
}
var domain = parent._domain || child._domain;
if ( domain ) {
child._domain = null;
runInDomain( domain, HandleCallback, cb, child, parent._value );
} else {
HandleCallback( cb, child, parent._value );
}
}
function HandleCallback( cb, promise, value ) {
var x;
try {
x = cb( value );
} catch ( e ) {
Settle( promise, REJECTED, e );
return;
}
Resolve( promise, x, true );
}
function resolverFor( promise ) {

@@ -315,3 +422,3 @@ var done = false;

done = true;
Resolve( promise, y );
Resolve( promise, y, false );
}

@@ -343,54 +450,23 @@ },

this._domain = null;
this._pending = [];
this._cb = null;
this._eb = null;
this._pending = null;
}
Promise.prototype.then = function( onFulfilled, onRejected ) {
var cb = typeof onFulfilled === "function" ? onFulfilled : null;
var eb = typeof onRejected === "function" ? onRejected : null;
var promise = new Promise();
var p = this;
var p2 = new Promise();
promise._cb = typeof onFulfilled === "function" ? onFulfilled : null;
promise._eb = typeof onRejected === "function" ? onRejected : null;
var thenDomain = isNodeJS && process.domain;
promise._domain = isNodeJS ? process.domain : null;
function onSettled() {
var func = p._state === FULFILLED ? cb : eb;
if ( !func ) {
Propagate( p, p2 );
return;
}
if ( this._state === PENDING ) {
Follow( promise, this );
var x, catched = false;
var d = p._domain || thenDomain;
if ( d ) {
if ( d._disposed ) return;
d.enter();
}
try {
x = func( p._value );
} catch ( e ) {
catched = true;
Settle( p2, REJECTED, e );
}
if ( !catched ) {
Resolve( p2, x );
}
if ( d ) {
d.exit();
}
}
if ( p._state === PENDING ) {
OnSettled( p, onSettled );
} else {
runLater( onSettled );
queueTask( false, Then, this, promise );
}
return p2;
return promise;
};

@@ -412,5 +488,9 @@

Promise.prototype._always = function( cb ) {
return this.then( cb, cb );
};
Promise.prototype.spread = function( cb, eb ) {
return this.then(cb && function( array ) {
return all( array, [] ).then(function( values ) {
return all( array ).then(function( values ) {
return apply.call( cb, void 0, values );

@@ -434,3 +514,3 @@ }, eb);

OnSettled(p, function() {
p._always(function() {
clearTimeout( timeoutId );

@@ -465,19 +545,8 @@ Propagate( p, p2 );

function valuesHandler( f ) {
function onFulfilled( values ) {
return f( values, [] );
}
function handleValues( values ) {
return P( values ).then( onFulfilled );
}
handleValues._ = f;
return handleValues;
}
P.allSettled = valuesHandler( allSettled );
function allSettled( input, output ) {
P.allSettled = allSettled;
function allSettled( input ) {
var waiting = 0;
var promise = new Promise();
var output = new Array( input.length );
forEach( input, function( x, index ) {

@@ -487,3 +556,3 @@ var p = P( x );

++waiting;
OnSettled(p, function() {
p._always(function() {
output[ index ] = p.inspect();

@@ -494,2 +563,3 @@ if ( --waiting === 0 ) {

});
} else {

@@ -499,12 +569,16 @@ output[ index ] = p.inspect();

});
if ( waiting === 0 ) {
Settle( promise, FULFILLED, output );
}
return promise;
}
P.all = valuesHandler( all );
function all( input, output ) {
P.all = all;
function all( input ) {
var waiting = 0;
var d = defer();
var output = new Array( input.length );
forEach( input, function( x, index ) {

@@ -525,5 +599,7 @@ var p = P( x );

});
if ( waiting === 0 ) {
d.resolve( output );
}
return d.promise;

@@ -539,4 +615,3 @@ }

return function() {
var allArgs = all( arguments, [] );
return all( [this, allArgs], [] ).then( onFulfilled );
return all([ this, all(arguments) ]).then( onFulfilled );
};

@@ -543,0 +618,0 @@ }

@@ -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=p(typeof process)&&{}.toString.call(process)==="[object process]",t=p(typeof setImmediate),n={f:null,n:null},r=n,i=false,o=e&&_||y(h)||w(h),u=[],f=w(d),a,c,s,l=p.call,v=p.apply;function p(e){return e==="object"||e==="function"}function d(){if(u.length){throw u.shift()}}function h(){while(n.n){n=n.n;var e=n.f;n.f=null;e.call()}i=false}var m=function(e){r=r.n={f:e,n:null};if(!i){i=true;o()}};function _(){var e=process.domain;if(e){if(!s)s=(1,require)("domain");s.active=process.domain=null}if(i&&t){setImmediate(h)}else{process.nextTick(h)}if(e){s.active=process.domain=e}}function y(e){var t=p(typeof MutationObserver)?new MutationObserver(e):p(typeof WebKitMutationObserver)?new WebKitMutationObserver(e):null;if(!t){return null}var n=1;var r=document.createTextNode("");t.observe(r,{characterData:true});return function(){n=-n;r.data=n}}function w(e){return function(){var t=setTimeout(r,0);var n=setInterval(r,50);function r(){clearTimeout(t);clearInterval(n);e()}}}if(e){a=function(e){var t=process.domain;return function(){if(t){if(t._disposed)return;t.enter()}try{e.call()}catch(n){o();throw n}if(t){t.exit()}}};c=function(e){var t=process.domain;m(!t?e:function(){if(!t._disposed){t.enter();e.call();t.exit()}})}}else{a=function(e){return function(){try{e.call()}catch(t){u.push(t);f()}}};c=m}function g(e){m(a(e))}function T(e,t){for(var n=0,r=e.length;n<r;++n){if(n in e){t(e[n],n)}}}function b(e){g(function(){if(I.onerror){I.onerror.call(null,e)}else{throw e}})}var j=0;var x=1;var O=2;function I(e){return e instanceof D?e:K(new D,e)}function M(t,n,r,i){if(t._state){return t}t._state=n;t._value=r;if(i){t._domain=i}else if(e&&n===O){t._domain=process.domain}if(t._pending.length){T(t._pending,m)}t._pending=null;return t}function E(e,t){e._pending.push(t)}function k(e,t){M(t,e._state,e._value,e._domain)}function K(e,t){if(e._state){return e}if(t instanceof D){if(t===e){M(e,O,new TypeError("You can't resolve a promise with itself"))}else if(t._state){k(t,e)}else{E(t,function(){k(t,e)})}}else if(t!==Object(t)){M(e,x,t)}else{c(function(){var n=S(e);try{var r=t.then;if(typeof r==="function"){l.call(r,t,n.resolve,n.reject)}else{M(e,x,t)}}catch(i){n.reject(i)}})}return e}function S(e){var t=false;return{promise:e,resolve:function(n){if(!t){t=true;K(e,n)}},reject:function(n){if(!t){t=true;M(e,O,n)}}}}I.defer=W;function W(){return S(new D)}I.reject=q;function q(e){return M(new D,O,e)}function D(){this._state=0;this._value=void 0;this._domain=null;this._pending=[]}D.prototype.then=function(t,n){var r=typeof t==="function"?t:null;var i=typeof n==="function"?n:null;var o=this;var u=new D;var f=e&&process.domain;function a(){var e=o._state===x?r:i;if(!e){k(o,u);return}var t,n=false;var a=o._domain||f;if(a){if(a._disposed)return;a.enter()}try{t=e(o._value)}catch(c){n=true;M(u,O,c)}if(!n){K(u,t)}if(a){a.exit()}}if(o._state===j){E(o,a)}else{m(a)}return u};D.prototype.done=function(e,t){var n=this;if(e||t){n=n.then(e,t)}n.then(null,b)};D.prototype.fail=function(e){return this.then(null,e)};D.prototype.spread=function(e,t){return this.then(e&&function(n){return Y(n,[]).then(function(t){return v.call(e,void 0,t)},t)},t)};D.prototype.timeout=function(e,t){var n=this;var r=new D;if(n._state!==j){k(n,r)}else{var i=setTimeout(function(){M(r,O,new Error(t||"Timed out after "+e+" ms"))},e);E(n,function(){clearTimeout(i);k(n,r)})}return r};D.prototype.delay=function(e){var t=W();this.then(function(n){setTimeout(function(){t.resolve(n)},e)},t.reject);return t.promise};D.prototype.inspect=function(){switch(this._state){case j:return{state:"pending"};case x:return{state:"fulfilled",value:this._value};case O:return{state:"rejected",reason:this._value};default:throw new TypeError("invalid state")}};function N(e){function t(t){return e(t,[])}function n(e){return I(e).then(t)}n._=e;return n}I.allSettled=N(P);function P(e,t){var n=0;var r=new D;T(e,function(e,i){var o=I(e);if(o._state===j){++n;E(o,function(){t[i]=o.inspect();if(--n===0){M(r,x,t)}})}else{t[i]=o.inspect()}});if(n===0){M(r,x,t)}return r}I.all=N(Y);function Y(e,t){var n=0;var r=W();T(e,function(e,i){var o=I(e);if(o._state===x){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}I.promised=z;function z(e){function t(t){return v.apply(e,t)}return function(){var e=Y(arguments,[]);return Y([this,e],[]).then(t)}}I.onerror=null;I.nextTick=g;return I});
(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=h(typeof process)&&process!=null&&{}.toString.call(process)==="[object process]",n=typeof setImmediate==="function",t=h(typeof MutationObserver)&&MutationObserver||h(typeof WebKitMutationObserver)&&WebKitMutationObserver,i=new v,r=i,o=false,u=0,a=e?g:t?x(m):T(m),l=[],s=T(_),f,c,p=h.call,d=h.apply;r.next=i;function v(){this.task=null;this.domain=null;this.a=null;this.b=null;this.next=null}function h(e){return e==="object"||e==="function"}function _(){if(l.length){throw l.shift()}}function m(){while(i!==r){i=i.next;var e=i.task;if(u>=1024){r.next=r.next.next}else{++u}if(i.domain){b(i.domain,e,i.a,i.b,void 0);i.domain=null}else{e(i.a,i.b)}i.task=null;i.a=null;i.b=null}o=false}function y(){i.task=null;i.domain=null;i.a=null;i.b=null;a()}function b(e,n,t,i,r){if(e._disposed){return}e.enter();n(t,i,r);e.exit()}function w(n,t,l,s){var f=r.next;if(f===i){f=new v;r.next=f;f.next=i}else{--u}r=f;f.task=t;f.a=l;f.b=s;if(n&&e){f.domain=process.domain}if(!o){o=true;a()}}function g(){var e=process.domain;if(e){if(!c)c=(1,require)("domain");c.active=process.domain=null}if(o&&n){setImmediate(m)}else{process.nextTick(m)}if(e){c.active=process.domain=e}}function x(e){var n=1;var i=document.createTextNode("");var r=new t(e);r.observe(i,{characterData:true});return function(){n=-n;i.data=n}}function T(e){return function(){var n=setTimeout(i,0);var t=setInterval(i,50);function i(){clearTimeout(n);clearInterval(t);e()}}}if(e){f=function(e){y();throw e}}else{f=function(e){l.push(e);s()}}function j(e,n){try{e.call()}catch(t){n(t)}}function k(e){w(true,j,e,f)}function O(e,n){for(var t=0,i=e.length;t<i;++t){if(t in e){n(e[t],t)}}}function I(e){k(function(){if(K.onerror){K.onerror.call(null,e)}else{throw e}})}var M=0;var E=1;var A=2;function K(e){return e instanceof G?e:q(new G,e,false)}function S(n,t,i){if(n._state){return n}n._state=t;n._value=i;if(t===A&&e){n._domain=process.domain}if(n._pending){N(n)}return n}function W(e,n){if(n._state){return n}n._state=e._state;n._value=e._value;n._domain=e._domain;if(n._pending){N(n)}return n}function q(e,n,t){if(e._state){return e}if(n instanceof G){if(n===e){S(e,A,new TypeError("You can't resolve a promise with itself"))}else if(n._state){W(n,e)}else{P(e,n)}}else if(n!==Object(n)){S(e,E,n)}else if(t){D(e,n)}else{w(true,D,e,n)}return e}function D(e,n){var t,i;try{i=n.then}catch(r){S(e,A,r);return}if(typeof i==="function"){t=B(e);try{p.call(i,n,t.resolve,t.reject)}catch(o){t.reject(o)}}else{S(e,E,n)}}function N(e){var n=e._pending;e._pending=null;if(n instanceof G){w(false,Y,e,n);return}for(var t=0,i=n.length;t<i;++t){w(false,Y,e,n[t])}}function P(e,n){if(!n._pending){n._pending=e}else if(n._pending instanceof G){n._pending=[n._pending,e]}else{n._pending.push(e)}}function Y(e,n){var t=e._state===E?n._cb:n._eb;n._cb=null;n._eb=null;if(!t){W(e,n);return}var i=e._domain||n._domain;if(i){n._domain=null;b(i,z,t,n,e._value)}else{z(t,n,e._value)}}function z(e,n,t){var i;try{i=e(t)}catch(r){S(n,A,r);return}q(n,i,true)}function B(e){var n=false;return{promise:e,resolve:function(t){if(!n){n=true;q(e,t,false)}},reject:function(t){if(!n){n=true;S(e,A,t)}}}}K.defer=C;function C(){return B(new G)}K.reject=F;function F(e){return S(new G,A,e)}function G(){this._state=0;this._value=void 0;this._domain=null;this._cb=null;this._eb=null;this._pending=null}G.prototype.then=function(n,t){var i=new G;i._cb=typeof n==="function"?n:null;i._eb=typeof t==="function"?t:null;i._domain=e?process.domain:null;if(this._state===M){P(i,this)}else{w(false,Y,this,i)}return i};G.prototype.done=function(e,n){var t=this;if(e||n){t=t.then(e,n)}t.then(null,I)};G.prototype.fail=function(e){return this.then(null,e)};G.prototype._always=function(e){return this.then(e,e)};G.prototype.spread=function(e,n){return this.then(e&&function(t){return J(t).then(function(n){return d.call(e,void 0,n)},n)},n)};G.prototype.timeout=function(e,n){var t=this;var i=new G;if(t._state!==M){W(t,i)}else{var r=setTimeout(function(){S(i,A,new Error(n||"Timed out after "+e+" ms"))},e);t._always(function(){clearTimeout(r);W(t,i)})}return i};G.prototype.delay=function(e){var n=C();this.then(function(t){setTimeout(function(){n.resolve(t)},e)},n.reject);return n.promise};G.prototype.inspect=function(){switch(this._state){case M:return{state:"pending"};case E:return{state:"fulfilled",value:this._value};case A:return{state:"rejected",reason:this._value};default:throw new TypeError("invalid state")}};K.allSettled=H;function H(e){var n=0;var t=new G;var i=new Array(e.length);O(e,function(e,r){var o=K(e);if(o._state===M){++n;o._always(function(){i[r]=o.inspect();if(--n===0){S(t,E,i)}})}else{i[r]=o.inspect()}});if(n===0){S(t,E,i)}return t}K.all=J;function J(e){var n=0;var t=C();var i=new Array(e.length);O(e,function(e,r){var o=K(e);if(o._state===E){i[r]=o._value}else{++n;o.then(function(e){i[r]=e;if(--n===0){t.resolve(i)}},t.reject)}});if(n===0){t.resolve(i)}return t.promise}K.promised=L;function L(e){function n(n){return d.apply(e,n)}return function(){return J([this,J(arguments)]).then(n)}}K.onerror=null;K.nextTick=k;return K});
{
"name": "p-promise",
"version": "0.3.2",
"version": "0.3.4",
"description": "A simple Promises/A+ library.",

@@ -5,0 +5,0 @@ "author": "Robert Katić <robert.katic@gmail.com> (https://github.com/rkatic)",

@@ -15,4 +15,6 @@ [![Build Status](https://travis-ci.org/rkatic/p.png?branch=master)](https://travis-ci.org/rkatic/p)

- Cross-Browser, Node.js and RequireJS ready.
- Supports domains (Note: domains in Node.js v0.8 are broken).
- Small.
- Simple.
- [Fast](http://jsperf.com/davy-jones-benchmark/29).

@@ -19,0 +21,0 @@ ##API

@@ -1,2 +0,2 @@

(function(){
"use strict";

@@ -6,7 +6,10 @@

global.P = require("../p");
var expect = require("expect.js");
var mocha = require("mocha");
global.expect = require("expect.js");
require("mocha");
}
var isNodeJS = typeof process === "object" && process &&
({}).toString.call(process) === "[object process]";
function fail() {

@@ -269,1 +272,51 @@ expect(true).to.be(false);

});
if ( isNodeJS && !/v0\.8\./.test(process.version) ) describe("domain", function() {
var domain = require("domain");
it("should work with domains", function() {
var d = P.defer();
var theValue = 0;
var theError = new Error();
P(47).then(function( value ) { theValue = value; });
var theDomain = domain.create();
theDomain.on("error", function( error ) {
expect( theValue ).to.be( 47 );
expect( error ).to.be( theError );
P().then( d.resolve );
})
.run(function() {
P().then(function() {
expect( domain.active ).to.be( theDomain );
}).done();
P.reject( theError ).done();
});
return d.promise.then(function() {
expect( domain.active ).not.to.be( theDomain );
}, fail);
});
it("should not evaluate promises in disposed domains", function() {
var theDomain = domain.create();
var called = false;
theDomain.on("error", function( e ) {
P().then(function() { called = true; });
theDomain.dispose();
})
.run(function() {
P.reject( new Error() ).done();
});
return P().delay(10).then(function() {
expect( called ).to.be( false );
});
});
});
})();

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc