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 2.5.1 to 3.0.0

.vscode/settings.json

29

package.json
{
"name": "zousan",
"version": "2.5.1",
"version": "3.0.0",
"description": "A Lightning Fast, Yet Very Small Promise A+ Compliant Implementation",
"main": "zousan-min.js",
"directories":
{
"module": "zousan-esm-min.js",
"directories": {
"test": "test"
},
"scripts":
{
"test": "cd test; npm install; npm test",
"build": "uglifyjs src/zousan.js -c -m -o zousan-min.js"
"scripts": {
"test": "cd test && npm install && npm test",
"buildUMD": "rollup src/zousan.js --format umd --name Zousan | uglifyjs -m -c > zousan-min.js",
"buildESM": "uglifyjs -m -c < src/zousan.js > zousan-esm-min.js",
"build": "npm run buildUMD && npm run buildESM"
},
"repository":
{
"repository": {
"type": "git",
"url": "git+https://github.com/bluejava/zousan.git"
},
"keywords":
[
"keywords": [
"promises-aplus",

@@ -26,11 +25,11 @@ "promise"

"devDependencies": {
"uglify-js": "latest"
"rollup": "^1.12.0",
"uglify-es": "mishoo/UglifyJS2#harmony"
},
"author": "Glenn Crownover <glenn@bluejava.com> (http://www.bluejava.com)",
"license": "MIT",
"bugs":
{
"bugs": {
"url": "https://github.com/bluejava/zousan/issues"
},
"homepage": "https://github.com/bluejava/zousan#readme"
}
}

@@ -23,5 +23,7 @@ <a href="http://promises-aplus.github.com/promises-spec">

**2019 Update:** As of version 3.0.0 we no longer define Zousan at the global level by default. (The exception being if you import the UMD version via `script` element without AMD present.)
## Usage
Zousan is defined as a UMD (Universal Module Definition), compliant with AMD and CommonJS module styles, as well as simple browser script includes which define `Zousan` globally.
Zousan is distributed both as an ES Module and as a UMD (Universal Module Definition), compliant with AMD and CommonJS module styles, as well as simple browser script includes which define `Zousan` globally.

@@ -28,0 +30,0 @@ Zousan is [Promise A+ 1.1](http://promises-aplus.github.com/promises-spec) compliant, so any documentation for spec-compliant promises applies to Zousan. There are a couple small additions though - see below. Briefly, the spec-compliant API is:

// zousan - A Lightning Fast, Yet Very Small Promise A+ Compliant Implementation
// https://github.com/bluejava/zousan
// Author: Glenn Crownover <glenn@bluejava.com> (http://www.bluejava.com)
// Version 2.5.0
// License: MIT
/* jshint asi: true, browser: true */
/* global setImmediate, console */
var STATE_PENDING, // 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
(function(global){
_undefined, // let the obfiscator compress these down
_undefinedString = "undefined"; // by assigning them to variables (debatable "optimization")
"use strict";
// See http://www.bluejava.com/4NS/Speed-up-your-Websites-with-a-Faster-setTimeout-using-soon
// This is a very fast "asynchronous" flow control - i.e. it yields the thread and executes later,
// but not much later. It is far faster and lighter than using setTimeout(fn,0) for yielding threads.
// Its also faster than other setImmediate shims, as it uses Mutation Observer and "mainlines" successive
// calls internally.
// WARNING: This does not yield to the browser UI loop, so by using this repeatedly
// you can starve the UI and be unresponsive to the user.
// This is an even FASTER version of https://gist.github.com/bluejava/9b9542d1da2a164d0456 that gives up
// passing context and arguments, in exchange for a 25x speed increase. (Use anon function to pass context/args)
var soon = (function() {
var
STATE_PENDING, // 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
var fq = [], // function queue;
fqStart = 0, // avoid using shift() by maintaining a start pointer - and remove items in chunks of 1024 (bufferSize)
bufferSize = 1024
_undefined, // let the obfiscator compress these down
_undefinedString = "undefined"; // by assigning them to variables (debatable "optimization")
function callQueue()
{
while(fq.length - fqStart) // this approach allows new yields to pile on during the execution of these
{
try { fq[fqStart]() } // no context or args..
catch(err) { if(global.console) global.console.error(err) }
fq[fqStart++] = _undefined // increase start pointer and dereference function just called
if(fqStart == bufferSize)
{
fq.splice(0,bufferSize);
fqStart = 0;
}
}
}
// See http://www.bluejava.com/4NS/Speed-up-your-Websites-with-a-Faster-setTimeout-using-soon
// This is a very fast "asynchronous" flow control - i.e. it yields the thread and executes later,
// but not much later. It is far faster and lighter than using setTimeout(fn,0) for yielding threads.
// Its also faster than other setImmediate shims, as it uses Mutation Observer and "mainlines" successive
// calls internally.
// WARNING: This does not yield to the browser UI loop, so by using this repeatedly
// you can starve the UI and be unresponsive to the user.
// This is an even FASTER version of https://gist.github.com/bluejava/9b9542d1da2a164d0456 that gives up
// passing context and arguments, in exchange for a 25x speed increase. (Use anon function to pass context/args)
var soon = (function() {
// run the callQueue function asyncrhonously, as fast as possible
var cqYield = (function() {
var fq = [], // function queue;
fqStart = 0, // avoid using shift() by maintaining a start pointer - and remove items in chunks of 1024 (bufferSize)
bufferSize = 1024
// This is the fastest way browsers have to yield processing
if(typeof MutationObserver !== _undefinedString)
{
// 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 });
function callQueue()
{
while(fq.length - fqStart) // this approach allows new yields to pile on during the execution of these
{
try { fq[fqStart]() } // no context or args..
catch(err) { if(global.console) global.console.error(err) }
fq[fqStart++] = _undefined // increase start pointer and dereference function just called
if(fqStart == bufferSize)
{
fq.splice(0,bufferSize);
fqStart = 0;
}
}
return function() { dd.setAttribute("a",0); } // trigger callback to
}
// run the callQueue function asyncrhonously, as fast as possible
var cqYield = (function() {
// if No MutationObserver - this is the next best thing for Node
if(typeof process !== _undefinedString && typeof process.nextTick === "function")
return function() { process.nextTick(callQueue) }
// This is the fastest way browsers have to yield processing
if(typeof MutationObserver !== _undefinedString)
{
// 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 });
// if No MutationObserver - this is the next best thing for MSIE
if(typeof setImmediate !== _undefinedString)
return function() { setImmediate(callQueue) }
return function() { dd.setAttribute("a",0); } // trigger callback to
}
// final fallback - shouldn't be used for much except very old browsers
return function() { setTimeout(callQueue,0) }
})();
// if No MutationObserver - this is the next best thing for Node
if(typeof process !== _undefinedString && typeof process.nextTick === "function")
return function() { process.nextTick(callQueue) }
// this is the function that will be assigned to soon
// it takes the function to call and examines all arguments
return function(fn) {
// if No MutationObserver - this is the next best thing for MSIE
if(typeof setImmediate !== _undefinedString)
return function() { setImmediate(callQueue) }
// push the function and any remaining arguments along with context
fq.push(fn);
// final fallback - shouldn't be used for much except very old browsers
return function() { setTimeout(callQueue,0) }
})();
if((fq.length - fqStart) == 1) // upon adding our first entry, kick off the callback
cqYield();
};
// this is the function that will be assigned to soon
// it takes the function to call and examines all arguments
return function(fn) {
})();
// push the function and any remaining arguments along with context
fq.push(fn);
// -------- BEGIN our main "class" definition here -------------
if((fq.length - fqStart) == 1) // upon adding our first entry, kick off the callback
cqYield();
};
function Zousan(func)
{
// 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>
})();
// If Zousan is called without "new", throw an error
if (!(this instanceof Zousan)) throw new TypeError("Zousan must be created with the new keyword");
// -------- BEGIN our main "class" definition here -------------
// If a function was specified, call it back with the resolve/reject functions bound to this context
if(typeof func === "function")
{
var 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
}
catch(e)
{
me.reject(e);
}
}
else if(arguments.length > 0) // If an argument was specified and it is NOT a function, throw an error
{
throw new TypeError("Zousan resolver " + func + " is not a function");
}
}
function Zousan(func)
Zousan.prototype = { // Add 6 functions to our prototype: "resolve", "reject", "then", "catch", "finally" and "timeout"
resolve: function(value)
{
// 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>
if(this.state !== STATE_PENDING)
return;
// 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(value === this)
return this.reject(new TypeError("Attempt to resolve promise with self"));
// If a function was specified, call it back with the resolve/reject functions bound to this context
if(typeof func === "function")
var me = this; // preserve this
if(value && (typeof value === "function" || typeof value === "object"))
{
var 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
var first = true; // first time through?
var then = value.then;
if(typeof then === "function")
{
// and call the value.then (which is now in "then") with value as the context and the resolve/reject functions per thenable spec
then.call(value,
function(ra) { if(first) { first=false; me.resolve(ra);} },
function(rr) { if(first) { first=false; me.reject(rr); } });
return;
}
}
catch(e)
{
me.reject(e);
if(first)
this.reject(e);
return;
}
}
else if(arguments.length > 0) // If an argument was specified and it is NOT a function, throw an error
{
throw new TypeError("Zousan resolver " + func + " is not a function");
}
}
Zousan.prototype = { // Add 6 functions to our prototype: "resolve", "reject", "then", "catch", "finally" and "timeout"
this.state = STATE_FULFILLED;
this.v = value;
resolve: function(value)
{
if(this.state !== STATE_PENDING)
return;
if(me.c)
soon(function() {
for(var n=0, l=me.c.length;n<l;n++)
resolveClient(me.c[n],value);
});
},
if(value === this)
return this.reject(new TypeError("Attempt to resolve promise with self"));
reject: function(reason)
{
if(this.state !== STATE_PENDING)
return;
var me = this; // preserve this
var me = this; // preserve this
if(value && (typeof value === "function" || typeof value === "object"))
{
try
{
var first = true; // first time through?
var then = value.then;
if(typeof then === "function")
{
// and call the value.then (which is now in "then") with value as the context and the resolve/reject functions per thenable spec
then.call(value,
function(ra) { if(first) { first=false; me.resolve(ra);} },
function(rr) { if(first) { first=false; me.reject(rr); } });
return;
}
}
catch(e)
{
if(first)
this.reject(e);
return;
}
this.state = STATE_REJECTED;
this.v = reason;
var clients = this.c;
if(clients)
soon(function() {
for(var n=0, l=clients.length;n<l;n++)
rejectClient(clients[n],reason);
});
else
soon(function() {
if(!me.handled) {
if(!Zousan.suppressUncaughtRejectionError && global.console)
Zousan.warn("You upset Zousan. Please catch rejections: ", reason,reason ? reason.stack : null)
}
});
},
this.state = STATE_FULFILLED;
this.v = value;
then: function(onF,onR)
{
var p = new Zousan();
var client = {y:onF,n:onR,p:p};
if(me.c)
soon(function() {
for(var n=0, l=me.c.length;n<l;n++)
resolveClient(me.c[n],value);
});
},
if(this.state === STATE_PENDING)
{
// we are pending, so client must wait - so push client to end of this.c array (create if necessary for efficiency)
if(this.c)
this.c.push(client);
else
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;
reject: function(reason)
{
if(this.state !== STATE_PENDING)
return;
// 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
var me = this; // preserve this
this.state = STATE_REJECTED;
this.v = reason;
var clients = this.c;
if(clients)
soon(function() {
for(var n=0, l=clients.length;n<l;n++)
rejectClient(clients[n],reason);
});
else
soon(function() {
if(!me.handled) {
if(!Zousan.suppressUncaughtRejectionError && global.console)
Zousan.warn("You upset Zousan. Please catch rejections: ", reason,reason ? reason.stack : null)
}
});
},
then: function(onF,onR)
{
var p = new Zousan();
var client = {y:onF,n:onR,p:p};
if(this.state === STATE_PENDING)
{
// we are pending, so client must wait - so push client to end of this.c array (create if necessary for efficiency)
if(this.c)
this.c.push(client);
soon(function() { // we are not pending, so yield script and resolve/reject as needed
if(s === STATE_FULFILLED)
resolveClient(client,a);
else
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;
rejectClient(client,a);
});
}
// 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
return p;
},
soon(function() { // we are not pending, so yield script and resolve/reject as needed
if(s === STATE_FULFILLED)
resolveClient(client,a);
else
rejectClient(client,a);
});
}
"catch": function(cfn) { return this.then(null,cfn); }, // convenience method
"finally": function(cfn) { return this.then(cfn,cfn); }, // convenience method
return p;
},
// new for 1.2 - this returns a new promise that times out if original promise does not resolve/reject before the time specified.
// Note: this has no effect on the original promise - which may still resolve/reject at a later time.
"timeout" : function(ms,timeoutMsg)
{
timeoutMsg = timeoutMsg || "Timeout"
var me = this;
return new Zousan(function(resolve,reject) {
"catch": function(cfn) { return this.then(null,cfn); }, // convenience method
"finally": function(cfn) { return this.then(cfn,cfn); }, // convenience method
setTimeout(function() {
reject(Error(timeoutMsg)); // This will fail silently if promise already resolved or rejected
}, ms);
// new for 1.2 - this returns a new promise that times out if original promise does not resolve/reject before the time specified.
// Note: this has no effect on the original promise - which may still resolve/reject at a later time.
"timeout" : function(ms,timeoutMsg)
{
timeoutMsg = timeoutMsg || "Timeout"
var me = this;
return new Zousan(function(resolve,reject) {
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
setTimeout(function() {
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
}; // END of prototype function list
})
}
}; // END of prototype function list
function resolveClient(c,arg)
{
if(typeof c.y === "function")
{
try {
var yret = c.y.call(_undefined,arg);
c.p.resolve(yret);
}
catch(err) { c.p.reject(err) }
function resolveClient(c,arg)
{
if(typeof c.y === "function")
{
try {
var yret = c.y.call(_undefined,arg);
c.p.resolve(yret);
}
else
c.p.resolve(arg); // pass this along...
}
catch(err) { c.p.reject(err) }
}
else
c.p.resolve(arg); // pass this along...
}
function rejectClient(c,reason)
function rejectClient(c,reason)
{
if(typeof c.n === "function")
{
try
{
if(typeof c.n === "function")
{
try
{
var yret = c.n.call(_undefined,reason);
c.p.resolve(yret);
}
catch(err) { c.p.reject(err) }
}
else
c.p.reject(reason); // pass this along...
var yret = c.n.call(_undefined,reason);
c.p.resolve(yret);
}
catch(err) { c.p.reject(err) }
}
else
c.p.reject(reason); // pass this along...
}
// "Class" functions follow (utility functions that live on the Zousan function object itself)
// "Class" functions follow (utility functions that live on the Zousan function object itself)
Zousan.resolve = function(val) { var z = new Zousan(); z.resolve(val); return z; }
Zousan.resolve = function(val) { var z = new Zousan(); z.resolve(val); return z; }
Zousan.reject = function(err) {
var z = new Zousan()
z.c=[] // see https://github.com/bluejava/zousan/issues/7#issuecomment-415394963
z.reject(err)
return z
}
Zousan.reject = function(err) {
var z = new Zousan()
z.c=[] // see https://github.com/bluejava/zousan/issues/7#issuecomment-415394963
z.reject(err)
return z
}
Zousan.all = function(pa)
{
var results = [ ], rc = 0, retP = new Zousan(); // results and resolved count
Zousan.all = function(pa)
{
var results = [ ], rc = 0, retP = new Zousan(); // results and resolved count
function rp(p,i)
{
if(!p || typeof p.then !== "function")
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 rp(p,i)
{
if(!p || typeof p.then !== "function")
p = Zousan.resolve(p);
p.then(
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(var x=0;x<pa.length;x++)
rp(pa[x],x);
// For zero length arrays, resolve immediately
if(!pa.length)
retP.resolve(results);
// For zero length arrays, resolve immediately
if(!pa.length)
retP.resolve(results);
return retP;
}
return retP;
}
Zousan.warn = console.warn
Zousan.warn = console.warn
// If this appears to be a commonJS environment, assign Zousan as the module export
if(typeof module != _undefinedString && module.exports) // jshint ignore:line
module.exports = Zousan; // jshint ignore:line
// make soon accessable from Zousan
Zousan.soon = soon
// If this appears to be an AMD environment, define Zousan as the module export
if(global.define && global.define.amd)
global.define([], function() { return Zousan });
// Make Zousan a global variable in all environments
global.Zousan = Zousan;
// make soon accessable from Zousan
Zousan.soon = soon;
})(typeof global != "undefined" ? global : this); // jshint ignore:line
export default Zousan

@@ -7,3 +7,3 @@ /* jshint asi: true */

var assert = require('assert'); // jshint ignore: line
var Zousan = require("../src/zousan.js");
var Zousan = require("..");

@@ -10,0 +10,0 @@ // Uncaught rejections occur within these tests as part of testing, so no need to report the error

@@ -8,3 +8,3 @@ {

],
"version": "1.2.1",
"version": "2.0.0",
"implements": [

@@ -11,0 +11,0 @@ "Zousan-Compliance-Testing"

@@ -6,3 +6,3 @@ /*

const Zousan = require("../src/zousan.js")
const Zousan = require("..")
const assert = require('assert')

@@ -9,0 +9,0 @@

@@ -12,3 +12,3 @@ /**

var promisesAplusTests = require("promises-aplus-tests");
var Zousan = require("../src/zousan.js");
var Zousan = require("..");

@@ -15,0 +15,0 @@ // By default, Zousan alerts you to uncaught rejections - a friendly heads-up

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

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

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