atomic-promise
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -1,2 +0,2 @@ | ||
/*! atomic-promise v0.0.1 https://github.com/falsandtru/atomic-promise | (c) 2018, falsandtru | (Apache-2.0 AND MPL-2.0) License */ | ||
/*! atomic-promise v0.0.2 https://github.com/falsandtru/atomic-promise | (c) 2018, falsandtru | (Apache-2.0 AND MPL-2.0) License */ | ||
require = function () { | ||
@@ -44,2 +44,16 @@ function r(e, n, t) { | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
function concat(target, source) { | ||
for (let i = 0, offset = target.length, len = source.length; i < len; ++i) { | ||
target[offset + i] = source[i]; | ||
} | ||
return target; | ||
} | ||
exports.concat = concat; | ||
}, | ||
{} | ||
], | ||
4: [ | ||
function (require, module, exports) { | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
function noop() { | ||
@@ -51,3 +65,3 @@ } | ||
], | ||
4: [ | ||
5: [ | ||
function (require, module, exports) { | ||
@@ -58,4 +72,10 @@ 'use strict'; | ||
'use strict'; | ||
const concat_1 = require('./concat'); | ||
const noop_1 = require('./noop'); | ||
const value = Symbol(); | ||
var State; | ||
(function (State) { | ||
State[State['resolved'] = 0] = 'resolved'; | ||
State[State['rejected'] = 1] = 'rejected'; | ||
}(State || (State = {}))); | ||
const status = Symbol(); | ||
const queue = Symbol(); | ||
@@ -68,11 +88,20 @@ const resume = Symbol(); | ||
try { | ||
void executor(val => { | ||
this[value] = this[value] || new PromiseValue('resolved', val); | ||
void executor(value => { | ||
this[status] = this[status] || [ | ||
0, | ||
value | ||
]; | ||
void this[resume](); | ||
}, reason => { | ||
this[value] = this[value] || new PromiseValue('rejected', reason); | ||
this[status] = this[status] || [ | ||
1, | ||
reason | ||
]; | ||
void this[resume](); | ||
}); | ||
} catch (reason) { | ||
this[value] = new PromiseValue('rejected', reason); | ||
this[status] = [ | ||
1, | ||
reason | ||
]; | ||
void this[resume](); | ||
@@ -85,6 +114,6 @@ } | ||
static all(values) { | ||
return values.reduce((acc, p) => acc.then(vs => AtomicPromise.resolve(p).then(value => vs.concat([value]))), AtomicPromise.resolve([])); | ||
return values.reduce((acc, value) => acc.then(vs => AtomicPromise.resolve(value).then(value => concat_1.concat(vs, [value]))), AtomicPromise.resolve([])); | ||
} | ||
static race(values) { | ||
return new AtomicPromise(resolve => void values.forEach(p => void AtomicPromise.resolve(p).then(resolve, resolve))); | ||
return new AtomicPromise((resolve, reject) => void values.forEach(value => void AtomicPromise.resolve(value).then(resolve, reject))); | ||
} | ||
@@ -98,13 +127,13 @@ static resolve(value) { | ||
[resume]() { | ||
const val = this[value]; | ||
if (!val) | ||
if (!this[status]) | ||
return; | ||
const [state, value] = this[status]; | ||
while (this[queue].length > 0) { | ||
const [resolve, reject] = this[queue].shift(); | ||
switch (val.state) { | ||
case 'resolved': | ||
isPromiseLike(val.value) ? void val.value.then(resolve, reject) : void resolve(val.value); | ||
switch (state) { | ||
case 0: | ||
isPromiseLike(value) ? void value.then(resolve, reject) : void resolve(value); | ||
continue; | ||
case 'rejected': | ||
void reject(val.value); | ||
case 1: | ||
void reject(value); | ||
continue; | ||
@@ -141,8 +170,2 @@ } | ||
exports.AtomicPromise = AtomicPromise; | ||
class PromiseValue { | ||
constructor(state, value) { | ||
this.state = state; | ||
this.value = value; | ||
} | ||
} | ||
function isPromiseLike(value) { | ||
@@ -152,3 +175,6 @@ return !!value && typeof value === 'object' && 'then' in value && typeof value.then === 'function'; | ||
}, | ||
{ './noop': 3 } | ||
{ | ||
'./concat': 3, | ||
'./noop': 4 | ||
} | ||
], | ||
@@ -166,3 +192,3 @@ 'atomic-promise': [ | ||
}, | ||
{ 'spica/promise': 4 } | ||
{ 'spica/promise': 5 } | ||
] | ||
@@ -175,11 +201,11 @@ }, {}, [ | ||
(function (root, factory) { | ||
if (typeof define === 'function' && define.amd) { | ||
define([], factory); | ||
} else if (typeof module === 'object' && module.exports) { | ||
module.exports = factory(); | ||
} else { | ||
root.returnExports = factory(); | ||
} | ||
if (typeof define === 'function' && define.amd) { | ||
define([], factory); | ||
} else if (typeof module === 'object' && module.exports) { | ||
module.exports = factory(); | ||
} else { | ||
Object.assign(root, factory()); | ||
} | ||
}(typeof self !== 'undefined' ? self : this, function () { | ||
return require('atomic-promise'); | ||
})); | ||
return require('atomic-promise'); | ||
})); |
@@ -1,2 +0,2 @@ | ||
/*! atomic-promise v0.0.1 https://github.com/falsandtru/atomic-promise | (c) 2018, falsandtru | (Apache-2.0 AND MPL-2.0) License */ | ||
require=function(){return function e(t,r,n){function o(s,c){if(!r[s]){if(!t[s]){var u="function"==typeof require&&require;if(!c&&u)return u(s,!0);if(i)return i(s,!0);var f=new Error("Cannot find module '"+s+"'");throw f.code="MODULE_NOT_FOUND",f}var a=r[s]={exports:{}};t[s][0].call(a.exports,function(e){return o(t[s][1][e]||e)},a,a.exports,e,t,r,n)}return r[s].exports}for(var i="function"==typeof require&&require,s=0;s<n.length;s++)o(n[s]);return o}}()({1:[function(e,t,r){},{}],2:[function(e,t,r){arguments[4][1][0].apply(r,arguments)},{dup:1}],3:[function(e,t,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.noop=function(){}},{}],4:[function(e,t,r){"use strict";var n;Object.defineProperty(r,"__esModule",{value:!0});const o=e("./noop"),i=Symbol(),s=Symbol(),c=Symbol();class u{constructor(e){this[Symbol.toStringTag]="Promise",this[n]=[];try{e(e=>{this[i]=this[i]||new f("resolved",e),this[c]()},e=>{this[i]=this[i]||new f("rejected",e),this[c]()})}catch(e){this[i]=new f("rejected",e),this[c]()}}static get[Symbol.species](){return u}static all(e){return e.reduce((e,t)=>e.then(e=>u.resolve(t).then(t=>e.concat([t]))),u.resolve([]))}static race(e){return new u(t=>void e.forEach(e=>void u.resolve(e).then(t,t)))}static resolve(e){return new u((t,r)=>a(e)?void e.then(t,r):void t(e))}static reject(e){return new u((t,r)=>void r(e))}[c](){const e=this[i];if(e)for(;this[s].length>0;){const[t,r]=this[s].shift();switch(e.state){case"resolved":a(e.value)?e.value.then(t,r):t(e.value);continue;case"rejected":r(e.value);continue}}}then(e,t){return e=e||u.resolve,t=t||u.reject,new u((r,n)=>{this[s].push([t=>{try{r(e(t))}catch(e){n(e)}},e=>void new u(r=>void r(t(e))).then(r,n)]),this[c]()})}catch(e){return this.then(void 0,e)}finally(e){return e=e||o.noop,this.then(t=>void e()||t,t=>void e()||u.reject(t))}}n=s,r.AtomicPromise=u;class f{constructor(e,t){this.state=e,this.value=t}}function a(e){return!!e&&"object"==typeof e&&"then"in e&&"function"==typeof e.then}},{"./noop":3}],"atomic-promise":[function(e,t,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),function(e){for(var t in e)r.hasOwnProperty(t)||(r[t]=e[t])}(e("spica/promise"))},{"spica/promise":4}]},{},[1,2,"atomic-promise"]),function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof module&&module.exports?module.exports=t():e.returnExports=t()}("undefined"!=typeof self?self:this,function(){return require("atomic-promise")}); | ||
/*! atomic-promise v0.0.2 https://github.com/falsandtru/atomic-promise | (c) 2018, falsandtru | (Apache-2.0 AND MPL-2.0) License */ | ||
require=function(){return function e(t,n,o){function r(c,s){if(!n[c]){if(!t[c]){var u="function"==typeof require&&require;if(!s&&u)return u(c,!0);if(i)return i(c,!0);var f=new Error("Cannot find module '"+c+"'");throw f.code="MODULE_NOT_FOUND",f}var h=n[c]={exports:{}};t[c][0].call(h.exports,function(e){return r(t[c][1][e]||e)},h,h.exports,e,t,n,o)}return n[c].exports}for(var i="function"==typeof require&&require,c=0;c<o.length;c++)r(o[c]);return r}}()({1:[function(e,t,n){},{}],2:[function(e,t,n){arguments[4][1][0].apply(n,arguments)},{dup:1}],3:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.concat=function(e,t){for(let n=0,o=e.length,r=t.length;n<r;++n)e[o+n]=t[n];return e}},{}],4:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.noop=function(){}},{}],5:[function(e,t,n){"use strict";var o;Object.defineProperty(n,"__esModule",{value:!0});const r=e("./concat"),i=e("./noop");var c;!function(e){e[e.resolved=0]="resolved",e[e.rejected=1]="rejected"}(c||(c={}));const s=Symbol(),u=Symbol(),f=Symbol();class h{constructor(e){this[Symbol.toStringTag]="Promise",this[o]=[];try{e(e=>{this[s]=this[s]||[0,e],this[f]()},e=>{this[s]=this[s]||[1,e],this[f]()})}catch(e){this[s]=[1,e],this[f]()}}static get[Symbol.species](){return h}static all(e){return e.reduce((e,t)=>e.then(e=>h.resolve(t).then(t=>r.concat(e,[t]))),h.resolve([]))}static race(e){return new h((t,n)=>void e.forEach(e=>void h.resolve(e).then(t,n)))}static resolve(e){return new h((t,n)=>a(e)?void e.then(t,n):void t(e))}static reject(e){return new h((t,n)=>void n(e))}[f](){if(!this[s])return;const[e,t]=this[s];for(;this[u].length>0;){const[n,o]=this[u].shift();switch(e){case 0:a(t)?t.then(n,o):n(t);continue;case 1:o(t);continue}}}then(e,t){return e=e||h.resolve,t=t||h.reject,new h((n,o)=>{this[u].push([t=>{try{n(e(t))}catch(e){o(e)}},e=>void new h(n=>void n(t(e))).then(n,o)]),this[f]()})}catch(e){return this.then(void 0,e)}finally(e){return e=e||i.noop,this.then(t=>void e()||t,t=>void e()||h.reject(t))}}function a(e){return!!e&&"object"==typeof e&&"then"in e&&"function"==typeof e.then}o=u,n.AtomicPromise=h},{"./concat":3,"./noop":4}],"atomic-promise":[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),function(e){for(var t in e)n.hasOwnProperty(t)||(n[t]=e[t])}(e("spica/promise"))},{"spica/promise":5}]},{},[1,2,"atomic-promise"]),function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof module&&module.exports?module.exports=t():Object.assign(e,t())}("undefined"!=typeof self?self:this,function(){return require("atomic-promise")}); |
import assert from 'power-assert'; | ||
import { AtomicPromise } from 'spica/promise'; | ||
@@ -7,2 +8,5 @@ type Assert = typeof assert; | ||
const assert: Assert; | ||
interface Window { | ||
AtomicPromise: typeof AtomicPromise; | ||
} | ||
} |
@@ -54,6 +54,6 @@ const gulp = require('gulp'); | ||
} else { | ||
root.returnExports = factory(); | ||
} | ||
Object.assign(root, factory()); | ||
} | ||
}(typeof self !== 'undefined' ? self : this, function () { | ||
return require('atomic-promise'); | ||
return require('${pkg.name}'); | ||
})); | ||
@@ -88,2 +88,3 @@ `, | ||
.once("finish", () => done || force || process.exit(1)) | ||
.pipe($.footer(config.module)) | ||
.pipe(gulp.dest(dest)); | ||
@@ -107,3 +108,2 @@ } | ||
.pipe($.header(config.banner)) | ||
.pipe($.footer(config.module)) | ||
.pipe(gulp.dest(config.ts.dist.dest)) | ||
@@ -110,0 +110,0 @@ .pipe($.rename({ extname: '.min.js' })) |
{ | ||
"name": "atomic-promise", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Promise with no delay.", | ||
@@ -29,6 +29,6 @@ "private": false, | ||
"dependencies": { | ||
"spica": "0.0.182" | ||
"spica": "0.0.188" | ||
}, | ||
"devDependencies": { | ||
"@types/mocha": "^5.2.0", | ||
"@types/mocha": "^5.2.1", | ||
"@types/power-assert": "^1.5.0", | ||
@@ -60,3 +60,3 @@ "browserify": "^16.2.2", | ||
"tsify": "^4.0.0", | ||
"typescript": "3.0.0-dev.20180522", | ||
"typescript": "3.0.0-dev.20180609", | ||
"uglify-es": "^3.3.9", | ||
@@ -63,0 +63,0 @@ "vinyl-buffer": "^1.0.1", |
@@ -7,2 +7,3 @@ import { AtomicPromise } from '../../index'; | ||
assert(typeof AtomicPromise === 'function'); | ||
assert(typeof window.AtomicPromise === 'function'); | ||
}); | ||
@@ -9,0 +10,0 @@ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
484933
13547
+ Addedspica@0.0.188(transitive)
- Removedspica@0.0.182(transitive)
Updatedspica@0.0.188