Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zousan

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zousan - npm Package Compare versions

Comparing version 3.0.0 to 3.0.1

2

package.json
{
"name": "zousan",
"version": "3.0.0",
"version": "3.0.1",
"description": "A Lightning Fast, Yet Very Small Promise A+ Compliant Implementation",

@@ -5,0 +5,0 @@ "main": "zousan-min.js",

@@ -6,8 +6,8 @@ // zousan - A Lightning Fast, Yet Very Small Promise A+ Compliant Implementation

var STATE_PENDING, // These are the three possible states (PENDING remains undefined - as intended)
const _undefined = undefined, // let the obfiscator compress these down
STATE_PENDING = _undefined, // These are the three possible states (PENDING remains undefined - as intended)
STATE_FULFILLED = "fulfilled", // a promise can be in. The state is stored
STATE_REJECTED = "rejected", // in this.state as read-only
_undefined, // let the obfiscator compress these down
_undefinedString = "undefined"; // by assigning them to variables (debatable "optimization")
_undefinedString = "undefined" // by assigning them to variables (debatable "optimization")

@@ -23,7 +23,7 @@ // See http://www.bluejava.com/4NS/Speed-up-your-Websites-with-a-Faster-setTimeout-using-soon

// passing context and arguments, in exchange for a 25x speed increase. (Use anon function to pass context/args)
var soon = (function() {
const soon = (() => {
var fq = [], // function queue;
fqStart = 0, // avoid using shift() by maintaining a start pointer - and remove items in chunks of 1024 (bufferSize)
const fq = [], // function queue
bufferSize = 1024
let fqStart = 0 // avoid using shift() by maintaining a start pointer - and remove items in chunks of 1024 (bufferSize)

@@ -35,8 +35,8 @@ function callQueue()

try { fq[fqStart]() } // no context or args..
catch(err) { if(global.console) global.console.error(err) }
catch(err) { Zousan.error(err) }
fq[fqStart++] = _undefined // increase start pointer and dereference function just called
if(fqStart == bufferSize)
{
fq.splice(0,bufferSize);
fqStart = 0;
fq.splice(0,bufferSize)
fqStart = 0
}

@@ -47,3 +47,3 @@ }

// run the callQueue function asyncrhonously, as fast as possible
var cqYield = (function() {
const cqYield = (() => {

@@ -54,7 +54,7 @@ // This is the fastest way browsers have to yield processing

// first, create a div not attached to DOM to "observe"
var dd = document.createElement("div");
var mo = new MutationObserver(callQueue);
mo.observe(dd, { attributes: true });
const dd = document.createElement("div")
const mo = new MutationObserver(callQueue)
mo.observe(dd, { attributes: true })
return function() { dd.setAttribute("a",0); } // trigger callback to
return function() { dd.setAttribute("a",0) } // trigger callback to
}

@@ -72,16 +72,16 @@

return function() { setTimeout(callQueue,0) }
})();
})()
// this is the function that will be assigned to soon
// it takes the function to call and examines all arguments
return function(fn) {
return fn => {
// push the function and any remaining arguments along with context
fq.push(fn);
fq.push(fn)
if((fq.length - fqStart) == 1) // upon adding our first entry, kick off the callback
cqYield();
};
cqYield()
}
})();
})()

@@ -93,6 +93,6 @@ // -------- BEGIN our main "class" definition here -------------

// this.state = STATE_PENDING; // Inital state (PENDING is undefined, so no need to actually have this assignment)
//this.c = []; // clients added while pending. <Since 1.0.2 this is lazy instantiation>
//this.c = [] // clients added while pending. <Since 1.0.2 this is lazy instantiation>
// If Zousan is called without "new", throw an error
if (!(this instanceof Zousan)) throw new TypeError("Zousan must be created with the new keyword");
if (!(this instanceof Zousan)) throw new TypeError("Zousan must be created with the new keyword")

@@ -102,12 +102,12 @@ // If a function was specified, call it back with the resolve/reject functions bound to this context

{
var me = this;
const me = this
try
{
func(
function(arg) { me.resolve(arg) }, // the resolve function bound to this context.
function(arg) { me.reject(arg) }) // the reject function bound to this context
arg => me.resolve(arg), // the resolve function bound to this context. (actually using bind() is slower)
arg => me.reject(arg)) // the reject function bound to this context
}
catch(e)
{
me.reject(e);
me.reject(e)
}

@@ -117,3 +117,3 @@ }

{
throw new TypeError("Zousan resolver " + func + " is not a function");
throw new TypeError("Zousan resolver " + func + " is not a function")
}

@@ -127,15 +127,15 @@ }

if(this.state !== STATE_PENDING)
return;
return
if(value === this)
return this.reject(new TypeError("Attempt to resolve promise with self"));
return this.reject(new TypeError("Attempt to resolve promise with self"))
var me = this; // preserve this
const me = this // preserve this
if(value && (typeof value === "function" || typeof value === "object"))
{
let first = true // first time through?
try
{
var first = true; // first time through?
var then = value.then;
const then = value.then
if(typeof then === "function")

@@ -145,5 +145,5 @@ {

then.call(value,
function(ra) { if(first) { first=false; me.resolve(ra);} },
function(rr) { if(first) { first=false; me.reject(rr); } });
return;
function(ra) { if(first) { first=false; me.resolve(ra)} },
function(rr) { if(first) { first=false; me.reject(rr) } })
return
}

@@ -154,15 +154,15 @@ }

if(first)
this.reject(e);
return;
this.reject(e)
return
}
}
this.state = STATE_FULFILLED;
this.v = value;
this.state = STATE_FULFILLED
this.v = value
if(me.c)
soon(function() {
for(var n=0, l=me.c.length;n<l;n++)
resolveClient(me.c[n],value);
});
for(let n=0, l=me.c.length;n<l;n++)
resolveClient(me.c[n],value)
})
},

@@ -173,22 +173,22 @@

if(this.state !== STATE_PENDING)
return;
return
var me = this; // preserve this
const me = this // preserve this
this.state = STATE_REJECTED;
this.v = reason;
this.state = STATE_REJECTED
this.v = reason
var clients = this.c;
const clients = this.c
if(clients)
soon(function() {
for(var n=0, l=clients.length;n<l;n++)
rejectClient(clients[n],reason);
});
for(let n=0, l=clients.length;n<l;n++)
rejectClient(clients[n],reason)
})
else
soon(function() {
if(!me.handled) {
if(!Zousan.suppressUncaughtRejectionError && global.console)
if(!Zousan.suppressUncaughtRejectionError)
Zousan.warn("You upset Zousan. Please catch rejections: ", reason,reason ? reason.stack : null)
}
});
})
},

@@ -198,4 +198,4 @@

{
var p = new Zousan();
var client = {y:onF,n:onR,p:p};
const p = new Zousan()
const client = {y:onF,n:onR,p:p}

@@ -206,26 +206,26 @@ if(this.state === STATE_PENDING)

if(this.c)
this.c.push(client);
this.c.push(client)
else
this.c = [client];
this.c = [client]
}
else // if state was NOT pending, then we can just immediately (soon) call the resolve/reject handler
{
var s = this.state, a = this.v;
const s = this.state, a = this.v
// In the case that the original promise is already fulfilled, any uncaught rejection should already have been warned about
this.handled = true; // set promise as "handled" to suppress warning for unhandled rejections
this.handled = true // set promise as "handled" to suppress warning for unhandled rejections
soon(function() { // we are not pending, so yield script and resolve/reject as needed
if(s === STATE_FULFILLED)
resolveClient(client,a);
resolveClient(client,a)
else
rejectClient(client,a);
});
rejectClient(client,a)
})
}
return p;
return p
},
"catch": function(cfn) { return this.then(null,cfn); }, // convenience method
"finally": function(cfn) { return this.then(cfn,cfn); }, // convenience method
"catch": function(cfn) { return this.then(null,cfn) }, // convenience method
"finally": function(cfn) { return this.then(cfn,cfn) }, // convenience method

@@ -237,11 +237,11 @@ // new for 1.2 - this returns a new promise that times out if original promise does not resolve/reject before the time specified.

timeoutMsg = timeoutMsg || "Timeout"
var me = this;
const me = this
return new Zousan(function(resolve,reject) {
setTimeout(function() {
reject(Error(timeoutMsg)); // This will fail silently if promise already resolved or rejected
}, ms);
reject(Error(timeoutMsg)) // This will fail silently if promise already resolved or rejected
}, ms)
me.then(function(v) { resolve(v) }, // This will fail silently if promise already timed out
function(er) { reject(er) }); // This will fail silently if promise already timed out
function(er) { reject(er) }) // This will fail silently if promise already timed out

@@ -251,3 +251,3 @@ })

}; // END of prototype function list
} // END of prototype function list

@@ -259,4 +259,4 @@ function resolveClient(c,arg)

try {
var yret = c.y.call(_undefined,arg);
c.p.resolve(yret);
const yret = c.y.call(_undefined,arg)
c.p.resolve(yret)
}

@@ -266,3 +266,3 @@ catch(err) { c.p.reject(err) }

else
c.p.resolve(arg); // pass this along...
c.p.resolve(arg) // pass this along...
}

@@ -276,4 +276,4 @@

{
var yret = c.n.call(_undefined,reason);
c.p.resolve(yret);
const yret = c.n.call(_undefined,reason)
c.p.resolve(yret)
}

@@ -283,3 +283,3 @@ catch(err) { c.p.reject(err) }

else
c.p.reject(reason); // pass this along...
c.p.reject(reason) // pass this along...
}

@@ -289,6 +289,6 @@

Zousan.resolve = function(val) { var z = new Zousan(); z.resolve(val); return z; }
Zousan.resolve = val => new Zousan(resolve => resolve(val))
Zousan.reject = function(err) {
var z = new Zousan()
const z = new Zousan()
z.c=[] // see https://github.com/bluejava/zousan/issues/7#issuecomment-415394963

@@ -301,3 +301,4 @@ z.reject(err)

{
var results = [ ], rc = 0, retP = new Zousan(); // results and resolved count
const results = [ ], retP = new Zousan() // results and final return promise
let rc = 0 // resolved count

@@ -307,20 +308,23 @@ function rp(p,i)

if(!p || typeof p.then !== "function")
p = Zousan.resolve(p);
p = Zousan.resolve(p)
p.then(
function(yv) { results[i] = yv; rc++; if(rc == pa.length) retP.resolve(results); },
function(nv) { retP.reject(nv); }
);
function(yv) { results[i] = yv; rc++; if(rc == pa.length) retP.resolve(results) },
function(nv) { retP.reject(nv) }
)
}
for(var x=0;x<pa.length;x++)
rp(pa[x],x);
for(let x=0;x<pa.length;x++)
rp(pa[x],x)
// For zero length arrays, resolve immediately
if(!pa.length)
retP.resolve(results);
retP.resolve(results)
return retP;
return retP
}
Zousan.warn = console.warn
// If we have a console, use it for our errors and warnings, else do nothing (either/both can be overwritten)
const nop = () => { }
Zousan.warn = typeof console !== _undefinedString ? console.warn : nop
Zousan.error = typeof console !== _undefinedString ? console.error : nop

@@ -327,0 +331,0 @@ // make soon accessable from Zousan

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

var STATE_PENDING,_undefined,STATE_FULFILLED="fulfilled",STATE_REJECTED="rejected",_undefinedString="undefined",soon=function(){var e=[],t=0,n=1024;function o(){for(;e.length-t;){try{e[t]()}catch(e){global.console&&global.console.error(e)}e[t++]=_undefined,t==n&&(e.splice(0,n),t=0)}}var r=function(){if(typeof MutationObserver!==_undefinedString){var e=document.createElement("div");return new MutationObserver(o).observe(e,{attributes:!0}),function(){e.setAttribute("a",0)}}return typeof process!==_undefinedString&&"function"==typeof process.nextTick?function(){process.nextTick(o)}:typeof setImmediate!==_undefinedString?function(){setImmediate(o)}:function(){setTimeout(o,0)}}();return function(n){e.push(n),e.length-t==1&&r()}}();function Zousan(e){if(!(this instanceof Zousan))throw new TypeError("Zousan must be created with the new keyword");if("function"==typeof e){var t=this;try{e(function(e){t.resolve(e)},function(e){t.reject(e)})}catch(e){t.reject(e)}}else if(arguments.length>0)throw new TypeError("Zousan resolver "+e+" is not a function")}function resolveClient(e,t){if("function"==typeof e.y)try{var n=e.y.call(_undefined,t);e.p.resolve(n)}catch(t){e.p.reject(t)}else e.p.resolve(t)}function rejectClient(e,t){if("function"==typeof e.n)try{var n=e.n.call(_undefined,t);e.p.resolve(n)}catch(t){e.p.reject(t)}else e.p.reject(t)}Zousan.prototype={resolve:function(e){if(this.state===STATE_PENDING){if(e===this)return this.reject(new TypeError("Attempt to resolve promise with self"));var t=this;if(e&&("function"==typeof e||"object"==typeof e))try{var n=!0,o=e.then;if("function"==typeof o)return void o.call(e,function(e){n&&(n=!1,t.resolve(e))},function(e){n&&(n=!1,t.reject(e))})}catch(e){return void(n&&this.reject(e))}this.state=STATE_FULFILLED,this.v=e,t.c&&soon(function(){for(var n=0,o=t.c.length;n<o;n++)resolveClient(t.c[n],e)})}},reject:function(e){if(this.state===STATE_PENDING){var t=this;this.state=STATE_REJECTED,this.v=e;var n=this.c;soon(n?function(){for(var t=0,o=n.length;t<o;t++)rejectClient(n[t],e)}:function(){t.handled||!Zousan.suppressUncaughtRejectionError&&global.console&&Zousan.warn("You upset Zousan. Please catch rejections: ",e,e?e.stack:null)})}},then:function(e,t){var n=new Zousan,o={y:e,n:t,p:n};if(this.state===STATE_PENDING)this.c?this.c.push(o):this.c=[o];else{var r=this.state,i=this.v;this.handled=!0,soon(function(){r===STATE_FULFILLED?resolveClient(o,i):rejectClient(o,i)})}return n},catch:function(e){return this.then(null,e)},finally:function(e){return this.then(e,e)},timeout:function(e,t){t=t||"Timeout";var n=this;return new Zousan(function(o,r){setTimeout(function(){r(Error(t))},e),n.then(function(e){o(e)},function(e){r(e)})})}},Zousan.resolve=function(e){var t=new Zousan;return t.resolve(e),t},Zousan.reject=function(e){var t=new Zousan;return t.c=[],t.reject(e),t},Zousan.all=function(e){var t=[],n=0,o=new Zousan;function r(r,i){r&&"function"==typeof r.then||(r=Zousan.resolve(r)),r.then(function(r){t[i]=r,++n==e.length&&o.resolve(t)},function(e){o.reject(e)})}for(var i=0;i<e.length;i++)r(e[i],i);return e.length||o.resolve(t),o},Zousan.warn=console.warn,Zousan.soon=soon;export default Zousan;
const _undefined=void 0,STATE_PENDING=_undefined,STATE_FULFILLED="fulfilled",STATE_REJECTED="rejected",_undefinedString="undefined",soon=(()=>{const e=[],t=1024;let n=0;function o(){for(;e.length-n;){try{e[n]()}catch(e){Zousan.error(e)}e[n++]=_undefined,n==t&&(e.splice(0,t),n=0)}}const s=(()=>{if("undefined"!=typeof MutationObserver){const e=document.createElement("div");return new MutationObserver(o).observe(e,{attributes:!0}),function(){e.setAttribute("a",0)}}return"undefined"!=typeof process&&"function"==typeof process.nextTick?function(){process.nextTick(o)}:"undefined"!=typeof setImmediate?function(){setImmediate(o)}:function(){setTimeout(o,0)}})();return t=>{e.push(t),e.length-n==1&&s()}})();function Zousan(e){if(!(this instanceof Zousan))throw new TypeError("Zousan must be created with the new keyword");if("function"==typeof e){const t=this;try{e(e=>t.resolve(e),e=>t.reject(e))}catch(e){t.reject(e)}}else if(arguments.length>0)throw new TypeError("Zousan resolver "+e+" is not a function")}function resolveClient(e,t){if("function"==typeof e.y)try{const n=e.y.call(_undefined,t);e.p.resolve(n)}catch(t){e.p.reject(t)}else e.p.resolve(t)}function rejectClient(e,t){if("function"==typeof e.n)try{const n=e.n.call(_undefined,t);e.p.resolve(n)}catch(t){e.p.reject(t)}else e.p.reject(t)}Zousan.prototype={resolve:function(e){if(this.state!==STATE_PENDING)return;if(e===this)return this.reject(new TypeError("Attempt to resolve promise with self"));const t=this;if(e&&("function"==typeof e||"object"==typeof e)){let n=!0;try{const o=e.then;if("function"==typeof o)return void o.call(e,function(e){n&&(n=!1,t.resolve(e))},function(e){n&&(n=!1,t.reject(e))})}catch(e){return void(n&&this.reject(e))}}this.state="fulfilled",this.v=e,t.c&&soon(function(){for(let n=0,o=t.c.length;n<o;n++)resolveClient(t.c[n],e)})},reject:function(e){if(this.state!==STATE_PENDING)return;const t=this;this.state="rejected",this.v=e;const n=this.c;soon(n?function(){for(let t=0,o=n.length;t<o;t++)rejectClient(n[t],e)}:function(){t.handled||Zousan.suppressUncaughtRejectionError||Zousan.warn("You upset Zousan. Please catch rejections: ",e,e?e.stack:null)})},then:function(e,t){const n=new Zousan,o={y:e,n:t,p:n};if(this.state===STATE_PENDING)this.c?this.c.push(o):this.c=[o];else{const e=this.state,t=this.v;this.handled=!0,soon(function(){"fulfilled"===e?resolveClient(o,t):rejectClient(o,t)})}return n},catch:function(e){return this.then(null,e)},finally:function(e){return this.then(e,e)},timeout:function(e,t){t=t||"Timeout";const n=this;return new Zousan(function(o,s){setTimeout(function(){s(Error(t))},e),n.then(function(e){o(e)},function(e){s(e)})})}},Zousan.resolve=(e=>new Zousan(t=>t(e))),Zousan.reject=function(e){const t=new Zousan;return t.c=[],t.reject(e),t},Zousan.all=function(e){const t=[],n=new Zousan;let o=0;function s(s,i){s&&"function"==typeof s.then||(s=Zousan.resolve(s)),s.then(function(s){t[i]=s,++o==e.length&&n.resolve(t)},function(e){n.reject(e)})}for(let t=0;t<e.length;t++)s(e[t],t);return e.length||n.resolve(t),n};const nop=()=>{};Zousan.warn="undefined"!=typeof console?console.warn:nop,Zousan.error="undefined"!=typeof console?console.error:nop,Zousan.soon=soon;export default Zousan;

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Zousan=t()}(this,function(){"use strict";var e,t=function(){var t=[],n=0,o=1024;function r(){for(;t.length-n;){try{t[n]()}catch(e){global.console&&global.console.error(e)}t[n++]=e,n==o&&(t.splice(0,o),n=0)}}var i=function(){if("undefined"!=typeof MutationObserver){var e=document.createElement("div");return new MutationObserver(r).observe(e,{attributes:!0}),function(){e.setAttribute("a",0)}}return"undefined"!=typeof process&&"function"==typeof process.nextTick?function(){process.nextTick(r)}:"undefined"!=typeof setImmediate?function(){setImmediate(r)}:function(){setTimeout(r,0)}}();return function(e){t.push(e),t.length-n==1&&i()}}();function n(e){if(!(this instanceof n))throw new TypeError("Zousan must be created with the new keyword");if("function"==typeof e){var t=this;try{e(function(e){t.resolve(e)},function(e){t.reject(e)})}catch(e){t.reject(e)}}else if(arguments.length>0)throw new TypeError("Zousan resolver "+e+" is not a function")}function o(t,n){if("function"==typeof t.y)try{var o=t.y.call(e,n);t.p.resolve(o)}catch(e){t.p.reject(e)}else t.p.resolve(n)}function r(t,n){if("function"==typeof t.n)try{var o=t.n.call(e,n);t.p.resolve(o)}catch(e){t.p.reject(e)}else t.p.reject(n)}return n.prototype={resolve:function(e){if(void 0===this.state){if(e===this)return this.reject(new TypeError("Attempt to resolve promise with self"));var n=this;if(e&&("function"==typeof e||"object"==typeof e))try{var r=!0,i=e.then;if("function"==typeof i)return void i.call(e,function(e){r&&(r=!1,n.resolve(e))},function(e){r&&(r=!1,n.reject(e))})}catch(e){return void(r&&this.reject(e))}this.state="fulfilled",this.v=e,n.c&&t(function(){for(var t=0,r=n.c.length;t<r;t++)o(n.c[t],e)})}},reject:function(e){if(void 0===this.state){var o=this;this.state="rejected",this.v=e;var i=this.c;t(i?function(){for(var t=0,n=i.length;t<n;t++)r(i[t],e)}:function(){o.handled||!n.suppressUncaughtRejectionError&&global.console&&n.warn("You upset Zousan. Please catch rejections: ",e,e?e.stack:null)})}},then:function(e,i){var c=new n,s={y:e,n:i,p:c};if(void 0===this.state)this.c?this.c.push(s):this.c=[s];else{var f=this.state,u=this.v;this.handled=!0,t(function(){"fulfilled"===f?o(s,u):r(s,u)})}return c},catch:function(e){return this.then(null,e)},finally:function(e){return this.then(e,e)},timeout:function(e,t){t=t||"Timeout";var o=this;return new n(function(n,r){setTimeout(function(){r(Error(t))},e),o.then(function(e){n(e)},function(e){r(e)})})}},n.resolve=function(e){var t=new n;return t.resolve(e),t},n.reject=function(e){var t=new n;return t.c=[],t.reject(e),t},n.all=function(e){var t=[],o=0,r=new n;function i(i,c){i&&"function"==typeof i.then||(i=n.resolve(i)),i.then(function(n){t[c]=n,++o==e.length&&r.resolve(t)},function(e){r.reject(e)})}for(var c=0;c<e.length;c++)i(e[c],c);return e.length||r.resolve(t),r},n.warn=console.warn,n.soon=t,n});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Zousan=e()}(this,function(){"use strict";const t=void 0,e=t,n=(()=>{const e=[],n=1024;let c=0;function i(){for(;e.length-c;){try{e[c]()}catch(t){o.error(t)}e[c++]=t,c==n&&(e.splice(0,n),c=0)}}const r=(()=>{if("undefined"!=typeof MutationObserver){const t=document.createElement("div");return new MutationObserver(i).observe(t,{attributes:!0}),function(){t.setAttribute("a",0)}}return"undefined"!=typeof process&&"function"==typeof process.nextTick?function(){process.nextTick(i)}:"undefined"!=typeof setImmediate?function(){setImmediate(i)}:function(){setTimeout(i,0)}})();return t=>{e.push(t),e.length-c==1&&r()}})();function o(t){if(!(this instanceof o))throw new TypeError("Zousan must be created with the new keyword");if("function"==typeof t){const e=this;try{t(t=>e.resolve(t),t=>e.reject(t))}catch(t){e.reject(t)}}else if(arguments.length>0)throw new TypeError("Zousan resolver "+t+" is not a function")}function c(e,n){if("function"==typeof e.y)try{const o=e.y.call(t,n);e.p.resolve(o)}catch(t){e.p.reject(t)}else e.p.resolve(n)}function i(e,n){if("function"==typeof e.n)try{const o=e.n.call(t,n);e.p.resolve(o)}catch(t){e.p.reject(t)}else e.p.reject(n)}o.prototype={resolve:function(t){if(this.state!==e)return;if(t===this)return this.reject(new TypeError("Attempt to resolve promise with self"));const o=this;if(t&&("function"==typeof t||"object"==typeof t)){let e=!0;try{const n=t.then;if("function"==typeof n)return void n.call(t,function(t){e&&(e=!1,o.resolve(t))},function(t){e&&(e=!1,o.reject(t))})}catch(t){return void(e&&this.reject(t))}}this.state="fulfilled",this.v=t,o.c&&n(function(){for(let e=0,n=o.c.length;e<n;e++)c(o.c[e],t)})},reject:function(t){if(this.state!==e)return;const c=this;this.state="rejected",this.v=t;const r=this.c;n(r?function(){for(let e=0,n=r.length;e<n;e++)i(r[e],t)}:function(){c.handled||o.suppressUncaughtRejectionError||o.warn("You upset Zousan. Please catch rejections: ",t,t?t.stack:null)})},then:function(t,r){const s=new o,f={y:t,n:r,p:s};if(this.state===e)this.c?this.c.push(f):this.c=[f];else{const t=this.state,e=this.v;this.handled=!0,n(function(){"fulfilled"===t?c(f,e):i(f,e)})}return s},catch:function(t){return this.then(null,t)},finally:function(t){return this.then(t,t)},timeout:function(t,e){e=e||"Timeout";const n=this;return new o(function(o,c){setTimeout(function(){c(Error(e))},t),n.then(function(t){o(t)},function(t){c(t)})})}},o.resolve=(t=>new o(e=>e(t))),o.reject=function(t){const e=new o;return e.c=[],e.reject(t),e},o.all=function(t){const e=[],n=new o;let c=0;function i(i,r){i&&"function"==typeof i.then||(i=o.resolve(i)),i.then(function(o){e[r]=o,++c==t.length&&n.resolve(e)},function(t){n.reject(t)})}for(let e=0;e<t.length;e++)i(t[e],e);return t.length||n.resolve(e),n};const r=()=>{};return o.warn="undefined"!=typeof console?console.warn:r,o.error="undefined"!=typeof console?console.error:r,o.soon=n,o});
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