@ndriadev/futurable 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -39
- package/dist/futurable.cjs.js +1 -0
- package/dist/futurable.mjs.js +326 -0
- package/dist/index.d.ts +104 -1
- package/dist/index.d.ts.map +1 -1
- package/package.json +5 -7
- package/dist/futurable.cjs +0 -1
- package/dist/futurable.mjs +0 -260
package/README.md
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
|
|
2
|
-
<h1 align="center">Futurable
|
|
2
|
+
<h1 align="center">Futurable<br/>Javascript's Promise API with super powers!</h1>
|
|
3
3
|
<p align="center">
|
|
4
4
|
Power up for Javascript's Promise API with cancellation support and more.
|
|
5
5
|
</p>
|
|
6
|
-
<div
|
|
6
|
+
<div style="display:flex; justify-content: center;">
|
|
7
7
|
|
|
8
|
-
[](https://www.npmjs.org/package/%40ndriadev/futurable)
|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
10
12
|
</div>
|
|
11
|
-
<div
|
|
13
|
+
<div style="display:flex; justify-content: center;">
|
|
12
14
|
|
|
13
|
-

|
|
16
|
+

|
|
17
|
+

|
|
18
|
+

|
|
17
19
|
</div>
|
|
18
20
|
|
|
19
21
|
|
|
@@ -27,21 +29,20 @@ Power up for Javascript's Promise API with cancellation support and more.
|
|
|
27
29
|
- [API](#API)
|
|
28
30
|
- [constructor](#constructor)
|
|
29
31
|
- [cancel](#cancel)
|
|
30
|
-
- [onCancel](#
|
|
31
|
-
- [sleep](#
|
|
32
|
-
- [delay](#
|
|
33
|
-
- [fetch](#
|
|
34
|
-
- [
|
|
35
|
-
- [
|
|
36
|
-
- [Futurable.
|
|
37
|
-
- [Futurable.
|
|
38
|
-
- [Futurable.
|
|
39
|
-
- [Futurable.
|
|
40
|
-
- [Futurable.
|
|
41
|
-
- [Futurable.
|
|
42
|
-
- [Futurable.
|
|
43
|
-
- [Futurable.race](#
|
|
44
|
-
- [Futurable.any](#Futurable.any)
|
|
32
|
+
- [onCancel](#oncancelcb-callback)
|
|
33
|
+
- [sleep](#sleeptimer-number)
|
|
34
|
+
- [delay](#delaycb-callback-timer-number)
|
|
35
|
+
- [fetch](#fetchurl-string--val--string-opts-object--requestinit)
|
|
36
|
+
- [futurizable](#futurizablepromise-promise--val--promise)
|
|
37
|
+
- [Futurable.onCancel](#futurableoncancelcb-callback--cb-callback-signal-abortsignal)
|
|
38
|
+
- [Futurable.sleep](#futurablesleeptimer-number--timer-number-signal-abortsignal)
|
|
39
|
+
- [Futurable.delay](#futurabledelaycb-callback-timer-number-signal-abortsignal)
|
|
40
|
+
- [Futurable.fetch](#futurablefetchurl-string-opts-object--requestinit)
|
|
41
|
+
- [Futurable.futurizable](#futurablefuturizablepromise-promise-signal-abortsignal)
|
|
42
|
+
- [Futurable.all](#futurablealliterable-futurableiterable-signal-abortsignal)
|
|
43
|
+
- [Futurable.allSettled](#futurableallsettlediterable-futurableiterable-signal-abortsignal)
|
|
44
|
+
- [Futurable.any](#futurableanyiterable-futurableiterable-signal-abortsignal)
|
|
45
|
+
- [Futurable.race](#futurableraceiterable-futurableiterable-signal-abortsignal)
|
|
45
46
|
- [License](#License)
|
|
46
47
|
|
|
47
48
|
|
|
@@ -125,20 +126,20 @@ The methods implemented, excluding those that are by nature static can be used:
|
|
|
125
126
|
|
|
126
127
|
They are the following:
|
|
127
128
|
- [cancel](#cancel)
|
|
128
|
-
- [onCancel](#
|
|
129
|
-
- [sleep](#
|
|
130
|
-
- [delay](#
|
|
131
|
-
- [fetch](#
|
|
132
|
-
- [futurizable](#
|
|
133
|
-
- [Futurable.onCancel](#
|
|
134
|
-
- [Futurable.sleep](#
|
|
135
|
-
- [Futurable.delay](#
|
|
136
|
-
- [Futurable.fetch](#
|
|
137
|
-
- [Futurable.futurizable](#
|
|
138
|
-
- [Futurable.all](#
|
|
139
|
-
- [Futurable.allSettled](
|
|
140
|
-
- [Futurable.
|
|
141
|
-
- [Futurable.
|
|
129
|
+
- [onCancel](#oncancelcb-callback)
|
|
130
|
+
- [sleep](#sleeptimer-number)
|
|
131
|
+
- [delay](#delaycb-callback-timer-number)
|
|
132
|
+
- [fetch](#fetchurl-string--val--string-opts-object--requestinit)
|
|
133
|
+
- [futurizable](#futurizablepromise-promise--val--promise)
|
|
134
|
+
- [Futurable.onCancel](#futurableoncancelcb-callback--cb-callback-signal-abortsignal)
|
|
135
|
+
- [Futurable.sleep](#futurablesleeptimer-number--timer-number-signal-abortsignal)
|
|
136
|
+
- [Futurable.delay](#futurabledelaycb-callback-timer-number-signal-abortsignal)
|
|
137
|
+
- [Futurable.fetch](#futurablefetchurl-string-opts-object--requestinit)
|
|
138
|
+
- [Futurable.futurizable](#futurablefuturizablepromise-promise-signal-abortsignal)
|
|
139
|
+
- [Futurable.all](#futurablealliterable-futurableiterable-signal-abortsignal)
|
|
140
|
+
- [Futurable.allSettled](#futurableallsettlediterable-futurableiterable-signal-abortsignal)
|
|
141
|
+
- [Futurable.any](#futurableanyiterable-futurableiterable-signal-abortsignal)
|
|
142
|
+
- [Futurable.race](#futurableraceiterable-futurableiterable-signal-abortsignal)
|
|
142
143
|
|
|
143
144
|
### constructor(executor: FuturableExecutor, signal?: AbortSignal)
|
|
144
145
|
Futurable is instantiable like a classic Promise.
|
|
@@ -282,6 +283,7 @@ futurable
|
|
|
282
283
|
|
|
283
284
|
### delay(cb: callback, timer: number)
|
|
284
285
|
Waits for timer parameter (in milliseconds), then executes callback with the futurable value and returns the result obtained from the invocation.
|
|
286
|
+
|
|
285
287
|
*Example*
|
|
286
288
|
```javascript
|
|
287
289
|
const futurable = new Futurable((resolve, reject, utils) => {
|
|
@@ -312,7 +314,7 @@ futurable
|
|
|
312
314
|
```
|
|
313
315
|
|
|
314
316
|
### fetch(url: string | (val => string), opts: object | RequestInit)
|
|
315
|
-
Extension of the fetch API with cancellation support. Url parameter can be a string or a function with receive value from futurable chaining as paremeter
|
|
317
|
+
Extension of the fetch API with cancellation support. Url parameter can be a string or a function with receive value from futurable chaining as paremeter.
|
|
316
318
|
|
|
317
319
|
*Example*
|
|
318
320
|
```javascript
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var P=Object.defineProperty;var z=(i,h,e)=>h in i?P(i,h,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[h]=e;var S=(i,h,e)=>(z(i,typeof h!="symbol"?h+"":h,e),e),D=(i,h,e)=>{if(!h.has(i))throw TypeError("Cannot "+e)};var C=(i,h,e)=>{if(h.has(i))throw TypeError("Cannot add the same private member more than once");h instanceof WeakSet?h.add(i):h.set(i,e)};var j=(i,h,e)=>(D(i,h,"access private method"),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var I=(i=>(i.PENDING="pending",i.FULFILLED="fulfilled",i.REJECTED="rejected",i))(I||{}),m,v;const s=class extends Promise{constructor(e,t){const r=t?null:new AbortController,n=t||r.signal,l=[],c=()=>{for(const a of l)clearTimeout(a)};let o;const u={signal:n,cancel:()=>{var a;return(a=this.controller)==null?void 0:a.abort()},onCancel:a=>{o=a},delay:(a,d)=>new s(g=>{l.push(setTimeout(()=>{g(a())},d))},n),sleep:a=>u.delay(()=>{},a),fetch:(a,d)=>new s((g,T)=>{fetch(a,{...d||{},signal:n}).then(b=>g(b)).catch(b=>{b.name!=="AbortError"&&T(b)})},n),futurizable:a=>new s((d,g)=>{a.then(d).catch(g)},n)};let y="pending";const E=new Promise((a,d)=>{if(n.aborted){c(),y==="pending"&&o&&o();return}else{const g=typeof n.onabort=="function"?n.onabort:()=>{};n.onabort=()=>{g(),c(),y==="pending"&&o&&o()},e(p=>{y="fulfilled",a(p)},p=>{y="rejected",d(p)},u)}});super((a,d)=>{E.then(g=>a(g)).catch(d)});C(this,m);S(this,"controller");S(this,"internalSignal");S(this,"idsTimeout");this.controller=r,this.internalSignal=n,this.idsTimeout=l}static get[Symbol.species](){return this}get[Symbol.toStringTag](){return"Futurable"}get signal(){return this.internalSignal}then(e,t){let r,n;const l=new s((c,o)=>{r=c,n=o},this.internalSignal);return l.controller=this.controller,super.then(c=>{var o;if((o=this.internalSignal)!=null&&o.aborted){j(this,m,v).call(this);return}try{r(e?e(c):c)}catch(f){n(f)}},c=>{var o;if((o=this.internalSignal)!=null&&o.aborted){j(this,m,v).call(this);return}try{t?r(t(c)):n(c)}catch(f){n(f)}}),l}catch(e){return this.then(null,e)}finally(e){return this.then(()=>{e()},()=>{e()})}cancel(){var e,t;!((e=this.internalSignal)!=null&&e.aborted)&&((t=this.controller)==null||t.abort())}delay(e,t){let r,n;const l=new s((c,o)=>{r=c,n=o},this.internalSignal);return l.controller=this.controller,this.then(c=>{this.idsTimeout.push(setTimeout(()=>r(e(c)),t))},c=>{n(c)}),l}sleep(e){return this.delay(t=>t,e)}fetch(e,t){let r,n;const l=new s((c,o)=>{r=c,n=o},this.internalSignal);return l.controller=this.controller,this.then(c=>{const o=typeof e=="function"?e(c):e,f={...typeof t=="function"?t(c):t,signal:this.internalSignal};fetch(o,f).then(u=>r(u)).catch(u=>{u.name!=="AbortError"&&n(u)})}),l}onCancel(e){let t,r;const n=new s((l,c,o)=>{o.onCancel(e),t=l,r=c},this.internalSignal);return n.controller=this.controller,this.then(l=>t(l),l=>r(l)),n}futurizable(e){let t,r;const n=new s((l,c)=>{t=l,r=c},this.internalSignal);return n.controller=this.controller,this.then(l=>{(typeof e=="function"?e(l):e).then(t).catch(r)}),n}static resolve(e,t){return new s(r=>r(e),t)}static reject(e,t){return new s((r,n)=>n(e),t)}static onCancel({cb:e,signal:t}){return new s((r,n,l)=>{l.onCancel(()=>r(e()))},t)}static delay({cb:e,timer:t,signal:r}){return s.resolve(!0,r).delay(e,t)}static sleep({timer:e,signal:t}){return s.delay({cb:()=>{},timer:e,signal:t})}static fetch(e,t){const r=(t==null?void 0:t.signal)||void 0;return t!=null&&t.signal&&delete t.signal,s.resolve(!0,r).fetch(e,t)}static futurizable({promise:e,signal:t}){return new s((r,n)=>{e.then(r).catch(n)},t)}static handleIterables(e,t){let r,n;const l=[],c=new s((o,f,u)=>{r=o,n=f,u.onCancel(()=>{for(const y of l)y.signal!==t&&y.cancel()})},t);t||(t=c.internalSignal);for(const o in e)e[o]instanceof s?l.push(e[o]):e[o]instanceof Promise?l.push(new s((f,u)=>{e[o].then(f).catch(u)},t)):l.push(s.resolve(e[o]));return{f:c,resolve:r,reject:n,array:l}}static all(e,t){const{f:r,resolve:n,reject:l,array:c}=s.handleIterables(e,t);return super.all(c).then(n).catch(l),r}static allSettled(e,t){const{f:r,resolve:n,reject:l,array:c}=s.handleIterables(e,t);return super.allSettled(c).then(n).catch(l),r}static race(e,t){const{f:r,resolve:n,reject:l,array:c}=s.handleIterables(e,t);return super.race(c).then(n).catch(l),r}static any(e,t){const{f:r,resolve:n,reject:l,array:c}=s.handleIterables(e,t);return super.any(c).then(n).catch(l),r}};let w=s;m=new WeakSet,v=function(){for(const e of this.idsTimeout)clearTimeout(e)};exports.FUTURABLE_STATUS=I;exports.Futurable=w;
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
var E = Object.defineProperty;
|
|
2
|
+
var P = (i, h, e) => h in i ? E(i, h, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[h] = e;
|
|
3
|
+
var p = (i, h, e) => (P(i, typeof h != "symbol" ? h + "" : h, e), e), z = (i, h, e) => {
|
|
4
|
+
if (!h.has(i))
|
|
5
|
+
throw TypeError("Cannot " + e);
|
|
6
|
+
};
|
|
7
|
+
var C = (i, h, e) => {
|
|
8
|
+
if (h.has(i))
|
|
9
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
10
|
+
h instanceof WeakSet ? h.add(i) : h.set(i, e);
|
|
11
|
+
};
|
|
12
|
+
var j = (i, h, e) => (z(i, h, "access private method"), e);
|
|
13
|
+
var D = /* @__PURE__ */ ((i) => (i.PENDING = "pending", i.FULFILLED = "fulfilled", i.REJECTED = "rejected", i))(D || {}), m, v;
|
|
14
|
+
const s = class extends Promise {
|
|
15
|
+
constructor(e, t) {
|
|
16
|
+
const r = t ? null : new AbortController(), n = t || r.signal, l = [], c = () => {
|
|
17
|
+
for (const a of l)
|
|
18
|
+
clearTimeout(a);
|
|
19
|
+
};
|
|
20
|
+
let o;
|
|
21
|
+
const u = {
|
|
22
|
+
signal: n,
|
|
23
|
+
cancel: () => {
|
|
24
|
+
var a;
|
|
25
|
+
return (a = this.controller) == null ? void 0 : a.abort();
|
|
26
|
+
},
|
|
27
|
+
onCancel: (a) => {
|
|
28
|
+
o = a;
|
|
29
|
+
},
|
|
30
|
+
delay: (a, d) => new s((g) => {
|
|
31
|
+
l.push(setTimeout(() => {
|
|
32
|
+
g(a());
|
|
33
|
+
}, d));
|
|
34
|
+
}, n),
|
|
35
|
+
sleep: (a) => u.delay(() => {
|
|
36
|
+
}, a),
|
|
37
|
+
fetch: (a, d) => new s((g, S) => {
|
|
38
|
+
fetch(a, { ...d || {}, signal: n }).then((b) => g(b)).catch((b) => {
|
|
39
|
+
b.name !== "AbortError" && S(b);
|
|
40
|
+
});
|
|
41
|
+
}, n),
|
|
42
|
+
futurizable: (a) => new s((d, g) => {
|
|
43
|
+
a.then(d).catch(g);
|
|
44
|
+
}, n)
|
|
45
|
+
};
|
|
46
|
+
let y = "pending";
|
|
47
|
+
const T = new Promise((a, d) => {
|
|
48
|
+
if (n.aborted) {
|
|
49
|
+
c(), y === "pending" && o && o();
|
|
50
|
+
return;
|
|
51
|
+
} else {
|
|
52
|
+
const g = typeof n.onabort == "function" ? n.onabort : () => {
|
|
53
|
+
};
|
|
54
|
+
n.onabort = () => {
|
|
55
|
+
g(), c(), y === "pending" && o && o();
|
|
56
|
+
}, e((w) => {
|
|
57
|
+
y = "fulfilled", a(w);
|
|
58
|
+
}, (w) => {
|
|
59
|
+
y = "rejected", d(w);
|
|
60
|
+
}, u);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
super((a, d) => {
|
|
64
|
+
T.then((g) => a(g)).catch(d);
|
|
65
|
+
});
|
|
66
|
+
C(this, m);
|
|
67
|
+
p(this, "controller");
|
|
68
|
+
p(this, "internalSignal");
|
|
69
|
+
p(this, "idsTimeout");
|
|
70
|
+
this.controller = r, this.internalSignal = n, this.idsTimeout = l;
|
|
71
|
+
}
|
|
72
|
+
static get [Symbol.species]() {
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
get [Symbol.toStringTag]() {
|
|
76
|
+
return "Futurable";
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Return internal futurable signal
|
|
80
|
+
*/
|
|
81
|
+
get signal() {
|
|
82
|
+
return this.internalSignal;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Attaches callbacks for the resolution and/or rejection of the Futurable.
|
|
86
|
+
*/
|
|
87
|
+
then(e, t) {
|
|
88
|
+
let r, n;
|
|
89
|
+
const l = new s((c, o) => {
|
|
90
|
+
r = c, n = o;
|
|
91
|
+
}, this.internalSignal);
|
|
92
|
+
return l.controller = this.controller, super.then((c) => {
|
|
93
|
+
var o;
|
|
94
|
+
if ((o = this.internalSignal) != null && o.aborted) {
|
|
95
|
+
j(this, m, v).call(this);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
r(e ? e(c) : c);
|
|
100
|
+
} catch (f) {
|
|
101
|
+
n(f);
|
|
102
|
+
}
|
|
103
|
+
}, (c) => {
|
|
104
|
+
var o;
|
|
105
|
+
if ((o = this.internalSignal) != null && o.aborted) {
|
|
106
|
+
j(this, m, v).call(this);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
t ? r(t(c)) : n(c);
|
|
111
|
+
} catch (f) {
|
|
112
|
+
n(f);
|
|
113
|
+
}
|
|
114
|
+
}), l;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Attaches a callback for only the rejection of the Futurable.
|
|
118
|
+
*/
|
|
119
|
+
catch(e) {
|
|
120
|
+
return this.then(null, e);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Attaches a callback that is invoked when the Futurable is settled (fulfilled or rejected). The resolved value cannot be modified from the callback.
|
|
124
|
+
*/
|
|
125
|
+
finally(e) {
|
|
126
|
+
return this.then(
|
|
127
|
+
() => {
|
|
128
|
+
e();
|
|
129
|
+
},
|
|
130
|
+
() => {
|
|
131
|
+
e();
|
|
132
|
+
}
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Cancel the futurable if it is to be executed or if it is still executing.
|
|
137
|
+
*/
|
|
138
|
+
cancel() {
|
|
139
|
+
var e, t;
|
|
140
|
+
!((e = this.internalSignal) != null && e.aborted) && ((t = this.controller) == null || t.abort());
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Waits for timer, then executes callback with the futurable value and returns the result obtained from the invocation.
|
|
144
|
+
* @param cb: callback executed after timer with futurable chain value as parameter
|
|
145
|
+
* @param timer: timer to wait (in milliseconds)
|
|
146
|
+
*/
|
|
147
|
+
delay(e, t) {
|
|
148
|
+
let r, n;
|
|
149
|
+
const l = new s((c, o) => {
|
|
150
|
+
r = c, n = o;
|
|
151
|
+
}, this.internalSignal);
|
|
152
|
+
return l.controller = this.controller, this.then(
|
|
153
|
+
(c) => {
|
|
154
|
+
this.idsTimeout.push(setTimeout(() => r(e(c)), t));
|
|
155
|
+
},
|
|
156
|
+
(c) => {
|
|
157
|
+
n(c);
|
|
158
|
+
}
|
|
159
|
+
), l;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Waits for timer parameter (in milliseconds) before returning the value.
|
|
163
|
+
* @param timer: timer to wait (in milliseconds)
|
|
164
|
+
*/
|
|
165
|
+
sleep(e) {
|
|
166
|
+
return this.delay((t) => t, e);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Extension of the fetch API with cancellation support. Url parameter can be a string or a function with receive value from futurable chaining as paremeter.
|
|
170
|
+
* @param url: url to fetch or function with futurable chaining value that returns url to fetch
|
|
171
|
+
* @param opts: fetch options or function with futurable chaining value that return fetch options
|
|
172
|
+
*/
|
|
173
|
+
fetch(e, t) {
|
|
174
|
+
let r, n;
|
|
175
|
+
const l = new s((c, o) => {
|
|
176
|
+
r = c, n = o;
|
|
177
|
+
}, this.internalSignal);
|
|
178
|
+
return l.controller = this.controller, this.then((c) => {
|
|
179
|
+
const o = typeof e == "function" ? e(c) : e, f = { ...typeof t == "function" ? t(c) : t, signal: this.internalSignal };
|
|
180
|
+
fetch(o, f).then((u) => r(u)).catch((u) => {
|
|
181
|
+
u.name !== "AbortError" && n(u);
|
|
182
|
+
});
|
|
183
|
+
}), l;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Executes the callback passed as a parameter when the futurable is cancelled.
|
|
187
|
+
* @param cb: callback
|
|
188
|
+
*/
|
|
189
|
+
onCancel(e) {
|
|
190
|
+
let t, r;
|
|
191
|
+
const n = new s((l, c, o) => {
|
|
192
|
+
o.onCancel(e), t = l, r = c;
|
|
193
|
+
}, this.internalSignal);
|
|
194
|
+
return n.controller = this.controller, this.then(
|
|
195
|
+
(l) => t(l),
|
|
196
|
+
(l) => r(l)
|
|
197
|
+
), n;
|
|
198
|
+
}
|
|
199
|
+
// promisify<TResult1 = T, TResult2 = never>(): Promise<TResult1 | TResult2> {
|
|
200
|
+
// return new Promise((res, rej) => {
|
|
201
|
+
// if (this.#signal.aborted) {
|
|
202
|
+
// this.#clearTimeout();
|
|
203
|
+
// return;
|
|
204
|
+
// } else {
|
|
205
|
+
// this.then(
|
|
206
|
+
// val => res(val),
|
|
207
|
+
// reason => rej(reason)
|
|
208
|
+
// );
|
|
209
|
+
// }
|
|
210
|
+
// });
|
|
211
|
+
// }
|
|
212
|
+
/**
|
|
213
|
+
* Takes a promise and transforms it into a futurizable. Promise can be also a function that receives value from futurable chaining as parameter.
|
|
214
|
+
* @param promise: Promise to futurize or function that return promise with futurable chaining value as parameter
|
|
215
|
+
*/
|
|
216
|
+
futurizable(e) {
|
|
217
|
+
let t, r;
|
|
218
|
+
const n = new s((l, c) => {
|
|
219
|
+
t = l, r = c;
|
|
220
|
+
}, this.internalSignal);
|
|
221
|
+
return n.controller = this.controller, this.then((l) => {
|
|
222
|
+
(typeof e == "function" ? e(l) : e).then(t).catch(r);
|
|
223
|
+
}), n;
|
|
224
|
+
}
|
|
225
|
+
static resolve(e, t) {
|
|
226
|
+
return new s((r) => r(e), t);
|
|
227
|
+
}
|
|
228
|
+
static reject(e, t) {
|
|
229
|
+
return new s((r, n) => n(e), t);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* OnCancel static method. It accepts a callback or a object with cb property and an optional signal.
|
|
233
|
+
*/
|
|
234
|
+
static onCancel({ cb: e, signal: t }) {
|
|
235
|
+
return new s((r, n, l) => {
|
|
236
|
+
l.onCancel(() => r(e()));
|
|
237
|
+
}, t);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Delay static method. It accepts a object with timer and cb properties and an optional signal property.
|
|
241
|
+
*/
|
|
242
|
+
static delay({ cb: e, timer: t, signal: r }) {
|
|
243
|
+
return s.resolve(!0, r).delay(e, t);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Sleep static method. It accepts a timer or a object with timer property and an optional signal.
|
|
247
|
+
*/
|
|
248
|
+
static sleep({ timer: e, signal: t }) {
|
|
249
|
+
return s.delay({
|
|
250
|
+
cb: () => {
|
|
251
|
+
},
|
|
252
|
+
timer: e,
|
|
253
|
+
signal: t
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Fetch static method.
|
|
258
|
+
*/
|
|
259
|
+
static fetch(e, t) {
|
|
260
|
+
const r = (t == null ? void 0 : t.signal) || void 0;
|
|
261
|
+
return t != null && t.signal && delete t.signal, s.resolve(!0, r).fetch(e, t);
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Futurizable static method.
|
|
265
|
+
*/
|
|
266
|
+
static futurizable({ promise: e, signal: t }) {
|
|
267
|
+
return new s((r, n) => {
|
|
268
|
+
e.then(r).catch(n);
|
|
269
|
+
}, t);
|
|
270
|
+
}
|
|
271
|
+
static handleIterables(e, t) {
|
|
272
|
+
let r, n;
|
|
273
|
+
const l = [], c = new s((o, f, u) => {
|
|
274
|
+
r = o, n = f, u.onCancel(() => {
|
|
275
|
+
for (const y of l)
|
|
276
|
+
y.signal !== t && y.cancel();
|
|
277
|
+
});
|
|
278
|
+
}, t);
|
|
279
|
+
t || (t = c.internalSignal);
|
|
280
|
+
for (const o in e)
|
|
281
|
+
e[o] instanceof s ? l.push(e[o]) : e[o] instanceof Promise ? l.push(new s((f, u) => {
|
|
282
|
+
e[o].then(f).catch(u);
|
|
283
|
+
}, t)) : l.push(s.resolve(e[o]));
|
|
284
|
+
return { f: c, resolve: r, reject: n, array: l };
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Creates a Futurable with cancellation support that is resolved with an array of results when all of the provided Futurables resolve, or rejected when any Futurable is rejected.
|
|
288
|
+
*/
|
|
289
|
+
static all(e, t) {
|
|
290
|
+
const { f: r, resolve: n, reject: l, array: c } = s.handleIterables(e, t);
|
|
291
|
+
return super.all(c).then(n).catch(l), r;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Creates a Futurable with cancellation support that is resolved with an array of results when all of the provided Futurables resolve or reject.
|
|
295
|
+
*/
|
|
296
|
+
static allSettled(e, t) {
|
|
297
|
+
const { f: r, resolve: n, reject: l, array: c } = s.handleIterables(e, t);
|
|
298
|
+
return super.allSettled(c).then(n).catch(l), r;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Creates a Futurable with cancellation support that is resolved or rejected when any of the provided Futurables are resolved or rejected.
|
|
302
|
+
*/
|
|
303
|
+
static race(e, t) {
|
|
304
|
+
const { f: r, resolve: n, reject: l, array: c } = s.handleIterables(e, t);
|
|
305
|
+
return super.race(c).then(n).catch(l), r;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* The any function returns a futurable with cancellation support that is fulfilled by the first given futurable to be fulfilled,
|
|
309
|
+
* or rejected with an AggregateError containing an array of rejection reasons if all of the
|
|
310
|
+
* given futurables are rejected. It resolves all elements of the passed iterable to futurables as
|
|
311
|
+
* it runs this algorithm.
|
|
312
|
+
*/
|
|
313
|
+
static any(e, t) {
|
|
314
|
+
const { f: r, resolve: n, reject: l, array: c } = s.handleIterables(e, t);
|
|
315
|
+
return super.any(c).then(n).catch(l), r;
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
let I = s;
|
|
319
|
+
m = new WeakSet(), v = function() {
|
|
320
|
+
for (const e of this.idsTimeout)
|
|
321
|
+
clearTimeout(e);
|
|
322
|
+
};
|
|
323
|
+
export {
|
|
324
|
+
D as FUTURABLE_STATUS,
|
|
325
|
+
I as Futurable
|
|
326
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -8,15 +8,47 @@ export interface FuturableReject {
|
|
|
8
8
|
(reason?: any): void;
|
|
9
9
|
}
|
|
10
10
|
export interface FuturableUtils<T> {
|
|
11
|
+
/**
|
|
12
|
+
* Internal futurable signal
|
|
13
|
+
*/
|
|
11
14
|
signal: AbortSignal;
|
|
15
|
+
/**
|
|
16
|
+
* Cancel the futurable if it is to be executed or if it is still executing.
|
|
17
|
+
*/
|
|
12
18
|
cancel: () => void;
|
|
19
|
+
/**
|
|
20
|
+
* Executes the callback passed as a parameter when the futurable is cancelled.
|
|
21
|
+
* @param cb: callback
|
|
22
|
+
*/
|
|
13
23
|
onCancel: (cb: () => void) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Waits for timer, then executes callback with the futurable value and returns the result obtained from the invocation.
|
|
26
|
+
* @param cb: callback executed after timer
|
|
27
|
+
* @param timer: timer to wait (in milliseconds)
|
|
28
|
+
*/
|
|
14
29
|
delay: (cb: () => any, timer: number) => Futurable<T>;
|
|
30
|
+
/**
|
|
31
|
+
* Waits for timer parameter (in milliseconds) before returning the value.
|
|
32
|
+
* @param timer: timer to wait (in milliseconds)
|
|
33
|
+
*/
|
|
15
34
|
sleep: (timer: number) => Futurable<T>;
|
|
35
|
+
/**
|
|
36
|
+
* Extension of the fetch API with cancellation support. Url parameter can be a string or a function with receive value from futurable chaining as paremeter.
|
|
37
|
+
* @param url: url to fetch
|
|
38
|
+
* @param opts: fetch options
|
|
39
|
+
*/
|
|
16
40
|
fetch: (url: string, opts?: RequestInit) => Futurable<T>;
|
|
41
|
+
/**
|
|
42
|
+
* Takes a promise and transforms it into a futurizable. Promise can be also a function that receives value from futurable chaining as parameter.
|
|
43
|
+
* @param promise: Promise to futurize
|
|
44
|
+
*/
|
|
17
45
|
futurizable: (promise: Promise<T>) => Futurable<T>;
|
|
18
46
|
}
|
|
19
|
-
export type FuturableExecutor<T> = (resolve: FuturableResolve<T>, reject: FuturableReject,
|
|
47
|
+
export type FuturableExecutor<T> = (resolve: FuturableResolve<T>, reject: FuturableReject,
|
|
48
|
+
/**
|
|
49
|
+
* Object containing implemented functionalities.
|
|
50
|
+
*/
|
|
51
|
+
utils: FuturableUtils<T>) => void;
|
|
20
52
|
export type FuturableIterable = Futurable<any> | Promise<any> | any;
|
|
21
53
|
export interface FuturableLike<T> {
|
|
22
54
|
then<TResult1 = T, TResult2 = never>(onfulfilled?: FuturableOnfulfilled<TResult1, TResult2>, onrejected?: FuturableOnrejected<TResult2>): FuturableLike<TResult1 | TResult2>;
|
|
@@ -28,42 +60,113 @@ export declare enum FUTURABLE_STATUS {
|
|
|
28
60
|
}
|
|
29
61
|
export declare class Futurable<T> extends Promise<T> {
|
|
30
62
|
#private;
|
|
63
|
+
private controller;
|
|
64
|
+
private internalSignal;
|
|
65
|
+
private idsTimeout;
|
|
31
66
|
constructor(executor: FuturableExecutor<T>, signal?: AbortSignal);
|
|
32
67
|
static get [Symbol.species](): typeof Futurable;
|
|
33
68
|
get [Symbol.toStringTag](): string;
|
|
69
|
+
/**
|
|
70
|
+
* Return internal futurable signal
|
|
71
|
+
*/
|
|
34
72
|
get signal(): AbortSignal;
|
|
73
|
+
/**
|
|
74
|
+
* Attaches callbacks for the resolution and/or rejection of the Futurable.
|
|
75
|
+
*/
|
|
35
76
|
then<TResult1 = T, TResult2 = never>(onFulfilled: FuturableOnfulfilled<TResult1, TResult2>, onRejected?: FuturableOnrejected<TResult2>): Futurable<TResult1 | TResult2>;
|
|
77
|
+
/**
|
|
78
|
+
* Attaches a callback for only the rejection of the Futurable.
|
|
79
|
+
*/
|
|
36
80
|
catch<TResult = never>(onRejected: FuturableOnrejected<TResult>): Futurable<T | TResult>;
|
|
81
|
+
/**
|
|
82
|
+
* Attaches a callback that is invoked when the Futurable is settled (fulfilled or rejected). The resolved value cannot be modified from the callback.
|
|
83
|
+
*/
|
|
37
84
|
finally(onFinally: () => void): Futurable<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Cancel the futurable if it is to be executed or if it is still executing.
|
|
87
|
+
*/
|
|
38
88
|
cancel(): void;
|
|
89
|
+
/**
|
|
90
|
+
* Waits for timer, then executes callback with the futurable value and returns the result obtained from the invocation.
|
|
91
|
+
* @param cb: callback executed after timer with futurable chain value as parameter
|
|
92
|
+
* @param timer: timer to wait (in milliseconds)
|
|
93
|
+
*/
|
|
39
94
|
delay<TResult1 = T, TResult2 = never>(cb: (val?: TResult1) => any, timer: number): Futurable<TResult1 | TResult2>;
|
|
95
|
+
/**
|
|
96
|
+
* Waits for timer parameter (in milliseconds) before returning the value.
|
|
97
|
+
* @param timer: timer to wait (in milliseconds)
|
|
98
|
+
*/
|
|
40
99
|
sleep<TResult1 = T, TResult2 = never>(timer: number): Futurable<TResult1 | TResult2>;
|
|
100
|
+
/**
|
|
101
|
+
* Extension of the fetch API with cancellation support. Url parameter can be a string or a function with receive value from futurable chaining as paremeter.
|
|
102
|
+
* @param url: url to fetch or function with futurable chaining value that returns url to fetch
|
|
103
|
+
* @param opts: fetch options or function with futurable chaining value that return fetch options
|
|
104
|
+
*/
|
|
41
105
|
fetch<TResult1 = T, TResult2 = never>(url: string | ((val?: TResult1) => string), opts?: object | RequestInit | ((val?: TResult1) => RequestInit)): Futurable<TResult1 | TResult2>;
|
|
106
|
+
/**
|
|
107
|
+
* Executes the callback passed as a parameter when the futurable is cancelled.
|
|
108
|
+
* @param cb: callback
|
|
109
|
+
*/
|
|
42
110
|
onCancel<TResult1 = T, TResult2 = never>(cb: () => void): Futurable<TResult1 | TResult2>;
|
|
111
|
+
/**
|
|
112
|
+
* Takes a promise and transforms it into a futurizable. Promise can be also a function that receives value from futurable chaining as parameter.
|
|
113
|
+
* @param promise: Promise to futurize or function that return promise with futurable chaining value as parameter
|
|
114
|
+
*/
|
|
43
115
|
futurizable<TResult1 = T, TResult2 = never>(promise: Promise<TResult1> | ((val?: TResult1) => Promise<TResult1>)): Futurable<TResult1 | TResult2>;
|
|
44
116
|
static resolve(value?: any, signal?: AbortSignal): Futurable<any>;
|
|
45
117
|
static reject(reason?: any, signal?: AbortSignal): Futurable<any>;
|
|
118
|
+
/**
|
|
119
|
+
* OnCancel static method. It accepts a callback or a object with cb property and an optional signal.
|
|
120
|
+
*/
|
|
46
121
|
static onCancel({ cb, signal }: {
|
|
47
122
|
cb: () => void;
|
|
48
123
|
signal?: AbortSignal;
|
|
49
124
|
}): Futurable<any>;
|
|
125
|
+
/**
|
|
126
|
+
* Delay static method. It accepts a object with timer and cb properties and an optional signal property.
|
|
127
|
+
*/
|
|
50
128
|
static delay({ cb, timer, signal }: {
|
|
51
129
|
cb: () => any;
|
|
52
130
|
timer: number;
|
|
53
131
|
signal?: AbortSignal;
|
|
54
132
|
}): Futurable<any>;
|
|
133
|
+
/**
|
|
134
|
+
* Sleep static method. It accepts a timer or a object with timer property and an optional signal.
|
|
135
|
+
*/
|
|
55
136
|
static sleep({ timer, signal }: {
|
|
56
137
|
timer: number;
|
|
57
138
|
signal?: AbortSignal;
|
|
58
139
|
}): Futurable<any>;
|
|
140
|
+
/**
|
|
141
|
+
* Fetch static method.
|
|
142
|
+
*/
|
|
59
143
|
static fetch(url: string, opts?: RequestInit): Futurable<any>;
|
|
144
|
+
/**
|
|
145
|
+
* Futurizable static method.
|
|
146
|
+
*/
|
|
60
147
|
static futurizable<TResult1 = any, TResult2 = never>({ promise, signal }: {
|
|
61
148
|
promise: Promise<TResult1>;
|
|
62
149
|
signal?: AbortSignal;
|
|
63
150
|
}): Futurable<TResult1 | TResult2>;
|
|
151
|
+
private static handleIterables;
|
|
152
|
+
/**
|
|
153
|
+
* Creates a Futurable with cancellation support that is resolved with an array of results when all of the provided Futurables resolve, or rejected when any Futurable is rejected.
|
|
154
|
+
*/
|
|
64
155
|
static all(iterables: FuturableIterable[], signal?: AbortSignal): Futurable<any>;
|
|
156
|
+
/**
|
|
157
|
+
* Creates a Futurable with cancellation support that is resolved with an array of results when all of the provided Futurables resolve or reject.
|
|
158
|
+
*/
|
|
65
159
|
static allSettled(iterables: FuturableIterable[], signal?: AbortSignal): Futurable<any>;
|
|
160
|
+
/**
|
|
161
|
+
* Creates a Futurable with cancellation support that is resolved or rejected when any of the provided Futurables are resolved or rejected.
|
|
162
|
+
*/
|
|
66
163
|
static race(iterables: FuturableIterable[], signal?: AbortSignal): Futurable<any>;
|
|
164
|
+
/**
|
|
165
|
+
* The any function returns a futurable with cancellation support that is fulfilled by the first given futurable to be fulfilled,
|
|
166
|
+
* or rejected with an AggregateError containing an array of rejection reasons if all of the
|
|
167
|
+
* given futurables are rejected. It resolves all elements of the passed iterable to futurables as
|
|
168
|
+
* it runs this algorithm.
|
|
169
|
+
*/
|
|
67
170
|
static any(iterables: FuturableIterable[], signal?: AbortSignal): Futurable<any>;
|
|
68
171
|
}
|
|
69
172
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,CAAC,CAAC,EAAE,QAAQ,GAAG,KAAK,IAAI,CAA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
"version": "1.0.
|
|
5
|
+
"version": "1.0.5",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
|
8
8
|
"node": ">=16.13.2"
|
|
@@ -14,14 +14,12 @@
|
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
|
16
16
|
"types": "./dist/index.d.ts",
|
|
17
|
-
"import": "./dist/futurable.mjs",
|
|
18
|
-
"require": "./dist/futurable.cjs",
|
|
19
|
-
"default": "./dist/futurable.mjs",
|
|
17
|
+
"import": "./dist/futurable.mjs.js",
|
|
18
|
+
"require": "./dist/futurable.cjs.js",
|
|
20
19
|
"node": {
|
|
21
20
|
"types": "./dist/index.d.ts",
|
|
22
|
-
"require": "./dist/futurable.cjs",
|
|
23
|
-
"import": "./dist/futurable.mjs"
|
|
24
|
-
"default": "./dist/futurable.cjs"
|
|
21
|
+
"require": "./dist/futurable.cjs.js",
|
|
22
|
+
"import": "./dist/futurable.mjs.js"
|
|
25
23
|
}
|
|
26
24
|
}
|
|
27
25
|
},
|
package/dist/futurable.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var I=(a,f,e)=>{if(!f.has(a))throw TypeError("Cannot "+e)};var l=(a,f,e)=>(I(a,f,"read from private field"),e?e.call(a):f.get(a)),C=(a,f,e)=>{if(f.has(a))throw TypeError("Cannot add the same private member more than once");f instanceof WeakSet?f.add(a):f.set(a,e)},p=(a,f,e,t)=>(I(a,f,"write to private field"),t?t.call(a,e):f.set(a,e),e);var w=(a,f,e)=>(I(a,f,"access private method"),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var x=(a=>(a.PENDING="pending",a.FULFILLED="fulfilled",a.REJECTED="rejected",a))(x||{}),u,d,T,S,L,v,P;const i=class extends Promise{constructor(e,t){const n=t?null:new AbortController,r=t||n.signal,s=[],o=()=>{for(const h of s)clearTimeout(h)};let c;const y={signal:r,cancel:()=>{var h;return(h=l(this,u))==null?void 0:h.abort()},onCancel:h=>{c=h},delay:(h,b)=>new i(m=>{s.push(setTimeout(()=>{m(h())},b))},r),sleep:h=>y.delay(()=>{},h),fetch:(h,b)=>new i((m,N)=>{fetch(h,{...b||{},signal:r}).then(E=>m(E)).catch(E=>{E.name!=="AbortError"&&N(E)})},r),futurizable:h=>new i((b,m)=>{h.then(b).catch(m)},r)};let j="pending";const A=new Promise((h,b)=>{if(r.aborted){o(),j==="pending"&&c&&c();return}else{const m=typeof r.onabort=="function"?r.onabort:()=>{};r.onabort=()=>{m(),o(),j==="pending"&&c&&c()},e(D=>{j="fulfilled",h(D)},D=>{j="rejected",b(D)},y)}});super((h,b)=>{A.then(m=>h(m)).catch(b)});C(this,S);C(this,u,void 0);C(this,d,void 0);C(this,T,void 0);p(this,u,n),p(this,d,r),p(this,T,s)}static get[Symbol.species](){return this}get[Symbol.toStringTag](){return"Futurable"}get signal(){return l(this,d)}then(e,t){let n,r;const s=new i((o,c)=>{n=o,r=c},l(this,d));return p(s,u,l(this,u)),super.then(o=>{var c;if((c=l(this,d))!=null&&c.aborted){w(this,S,L).call(this);return}try{n(e?e(o):o)}catch(g){r(g)}},o=>{var c;if((c=l(this,d))!=null&&c.aborted){w(this,S,L).call(this);return}try{t?n(t(o)):r(o)}catch(g){r(g)}}),s}catch(e){return this.then(null,e)}finally(e){return this.then(()=>{e()},()=>{e()})}cancel(){var e,t;!((e=l(this,d))!=null&&e.aborted)&&((t=l(this,u))==null||t.abort())}delay(e,t){let n,r;const s=new i((o,c)=>{n=o,r=c},l(this,d));return p(s,u,l(this,u)),this.then(o=>{l(this,T).push(setTimeout(()=>n(e(o)),t))},o=>{r(o)}),s}sleep(e){return this.delay(t=>t,e)}fetch(e,t){let n,r;const s=new i((o,c)=>{n=o,r=c},l(this,d));return p(s,u,l(this,u)),this.then(o=>{const c=typeof e=="function"?e(o):e,g={...typeof t=="function"?t(o):t,signal:l(this,d)};fetch(c,g).then(y=>n(y)).catch(y=>{y.name!=="AbortError"&&r(y)})}),s}onCancel(e){let t,n;const r=new i((s,o,c)=>{c.onCancel(e),t=s,n=o},l(this,d));return p(r,u,l(this,u)),this.then(s=>t(s),s=>n(s)),r}futurizable(e){let t,n;const r=new i((s,o)=>{t=s,n=o},l(this,d));return p(r,u,l(this,u)),this.then(s=>{(typeof e=="function"?e(s):e).then(t).catch(n)}),r}static resolve(e,t){return new i(n=>n(e),t)}static reject(e,t){return new i((n,r)=>r(e),t)}static onCancel({cb:e,signal:t}){return new i((n,r,s)=>{s.onCancel(()=>n(e()))},t)}static delay({cb:e,timer:t,signal:n}){return i.resolve(!0,n).delay(e,t)}static sleep({timer:e,signal:t}){return i.delay({cb:()=>{},timer:e,signal:t})}static fetch(e,t){const n=(t==null?void 0:t.signal)||void 0;return t!=null&&t.signal&&delete t.signal,i.resolve(!0,n).fetch(e,t)}static futurizable({promise:e,signal:t}){return new i((n,r)=>{e.then(n).catch(r)},t)}static all(e,t){var c;const{f:n,resolve:r,reject:s,array:o}=w(c=i,v,P).call(c,e,t);return super.all(o).then(r).catch(s),n}static allSettled(e,t){var c;const{f:n,resolve:r,reject:s,array:o}=w(c=i,v,P).call(c,e,t);return super.allSettled(o).then(r).catch(s),n}static race(e,t){var c;const{f:n,resolve:r,reject:s,array:o}=w(c=i,v,P).call(c,e,t);return super.race(o).then(r).catch(s),n}static any(e,t){var c;const{f:n,resolve:r,reject:s,array:o}=w(c=i,v,P).call(c,e,t);return super.any(o).then(r).catch(s),n}};let z=i;u=new WeakMap,d=new WeakMap,T=new WeakMap,S=new WeakSet,L=function(){for(const e of l(this,T))clearTimeout(e)},v=new WeakSet,P=function(e,t){let n,r;const s=[],o=new i((c,g,y)=>{n=c,r=g,y.onCancel(()=>{for(const j of s)j.signal!==t&&j.cancel()})},t);t||(t=o.signal);for(const c in e)e[c]instanceof i?s.push(e[c]):e[c]instanceof Promise?s.push(new i((g,y)=>{e[c].then(g).catch(y)},t)):s.push(i.resolve(e[c]));return{f:o,resolve:n,reject:r,array:s}},C(z,v);exports.FUTURABLE_STATUS=x;exports.Futurable=z;
|
package/dist/futurable.mjs
DELETED
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
var I = (a, f, e) => {
|
|
2
|
-
if (!f.has(a))
|
|
3
|
-
throw TypeError("Cannot " + e);
|
|
4
|
-
};
|
|
5
|
-
var l = (a, f, e) => (I(a, f, "read from private field"), e ? e.call(a) : f.get(a)), C = (a, f, e) => {
|
|
6
|
-
if (f.has(a))
|
|
7
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
8
|
-
f instanceof WeakSet ? f.add(a) : f.set(a, e);
|
|
9
|
-
}, w = (a, f, e, t) => (I(a, f, "write to private field"), t ? t.call(a, e) : f.set(a, e), e);
|
|
10
|
-
var j = (a, f, e) => (I(a, f, "access private method"), e);
|
|
11
|
-
var L = /* @__PURE__ */ ((a) => (a.PENDING = "pending", a.FULFILLED = "fulfilled", a.REJECTED = "rejected", a))(L || {}), u, d, E, z, N, v, T;
|
|
12
|
-
const i = class extends Promise {
|
|
13
|
-
constructor(e, t) {
|
|
14
|
-
const n = t ? null : new AbortController(), r = t || n.signal, s = [], o = () => {
|
|
15
|
-
for (const h of s)
|
|
16
|
-
clearTimeout(h);
|
|
17
|
-
};
|
|
18
|
-
let c;
|
|
19
|
-
const y = {
|
|
20
|
-
signal: r,
|
|
21
|
-
cancel: () => {
|
|
22
|
-
var h;
|
|
23
|
-
return (h = l(this, u)) == null ? void 0 : h.abort();
|
|
24
|
-
},
|
|
25
|
-
onCancel: (h) => {
|
|
26
|
-
c = h;
|
|
27
|
-
},
|
|
28
|
-
delay: (h, p) => new i((m) => {
|
|
29
|
-
s.push(setTimeout(() => {
|
|
30
|
-
m(h());
|
|
31
|
-
}, p));
|
|
32
|
-
}, r),
|
|
33
|
-
sleep: (h) => y.delay(() => {
|
|
34
|
-
}, h),
|
|
35
|
-
fetch: (h, p) => new i((m, G) => {
|
|
36
|
-
fetch(h, { ...p || {}, signal: r }).then((P) => m(P)).catch((P) => {
|
|
37
|
-
P.name !== "AbortError" && G(P);
|
|
38
|
-
});
|
|
39
|
-
}, r),
|
|
40
|
-
futurizable: (h) => new i((p, m) => {
|
|
41
|
-
h.then(p).catch(m);
|
|
42
|
-
}, r)
|
|
43
|
-
};
|
|
44
|
-
let b = "pending";
|
|
45
|
-
const J = new Promise((h, p) => {
|
|
46
|
-
if (r.aborted) {
|
|
47
|
-
o(), b === "pending" && c && c();
|
|
48
|
-
return;
|
|
49
|
-
} else {
|
|
50
|
-
const m = typeof r.onabort == "function" ? r.onabort : () => {
|
|
51
|
-
};
|
|
52
|
-
r.onabort = () => {
|
|
53
|
-
m(), o(), b === "pending" && c && c();
|
|
54
|
-
}, e((D) => {
|
|
55
|
-
b = "fulfilled", h(D);
|
|
56
|
-
}, (D) => {
|
|
57
|
-
b = "rejected", p(D);
|
|
58
|
-
}, y);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
super((h, p) => {
|
|
62
|
-
J.then((m) => h(m)).catch(p);
|
|
63
|
-
});
|
|
64
|
-
C(this, z);
|
|
65
|
-
C(this, u, void 0);
|
|
66
|
-
C(this, d, void 0);
|
|
67
|
-
C(this, E, void 0);
|
|
68
|
-
w(this, u, n), w(this, d, r), w(this, E, s);
|
|
69
|
-
}
|
|
70
|
-
static get [Symbol.species]() {
|
|
71
|
-
return this;
|
|
72
|
-
}
|
|
73
|
-
get [Symbol.toStringTag]() {
|
|
74
|
-
return "Futurable";
|
|
75
|
-
}
|
|
76
|
-
get signal() {
|
|
77
|
-
return l(this, d);
|
|
78
|
-
}
|
|
79
|
-
then(e, t) {
|
|
80
|
-
let n, r;
|
|
81
|
-
const s = new i((o, c) => {
|
|
82
|
-
n = o, r = c;
|
|
83
|
-
}, l(this, d));
|
|
84
|
-
return w(s, u, l(this, u)), super.then((o) => {
|
|
85
|
-
var c;
|
|
86
|
-
if ((c = l(this, d)) != null && c.aborted) {
|
|
87
|
-
j(this, z, N).call(this);
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
try {
|
|
91
|
-
n(e ? e(o) : o);
|
|
92
|
-
} catch (g) {
|
|
93
|
-
r(g);
|
|
94
|
-
}
|
|
95
|
-
}, (o) => {
|
|
96
|
-
var c;
|
|
97
|
-
if ((c = l(this, d)) != null && c.aborted) {
|
|
98
|
-
j(this, z, N).call(this);
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
try {
|
|
102
|
-
t ? n(t(o)) : r(o);
|
|
103
|
-
} catch (g) {
|
|
104
|
-
r(g);
|
|
105
|
-
}
|
|
106
|
-
}), s;
|
|
107
|
-
}
|
|
108
|
-
catch(e) {
|
|
109
|
-
return this.then(null, e);
|
|
110
|
-
}
|
|
111
|
-
finally(e) {
|
|
112
|
-
return this.then(
|
|
113
|
-
() => {
|
|
114
|
-
e();
|
|
115
|
-
},
|
|
116
|
-
() => {
|
|
117
|
-
e();
|
|
118
|
-
}
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
cancel() {
|
|
122
|
-
var e, t;
|
|
123
|
-
!((e = l(this, d)) != null && e.aborted) && ((t = l(this, u)) == null || t.abort());
|
|
124
|
-
}
|
|
125
|
-
delay(e, t) {
|
|
126
|
-
let n, r;
|
|
127
|
-
const s = new i((o, c) => {
|
|
128
|
-
n = o, r = c;
|
|
129
|
-
}, l(this, d));
|
|
130
|
-
return w(s, u, l(this, u)), this.then(
|
|
131
|
-
(o) => {
|
|
132
|
-
l(this, E).push(setTimeout(() => n(e(o)), t));
|
|
133
|
-
},
|
|
134
|
-
(o) => {
|
|
135
|
-
r(o);
|
|
136
|
-
}
|
|
137
|
-
), s;
|
|
138
|
-
}
|
|
139
|
-
sleep(e) {
|
|
140
|
-
return this.delay((t) => t, e);
|
|
141
|
-
}
|
|
142
|
-
fetch(e, t) {
|
|
143
|
-
let n, r;
|
|
144
|
-
const s = new i((o, c) => {
|
|
145
|
-
n = o, r = c;
|
|
146
|
-
}, l(this, d));
|
|
147
|
-
return w(s, u, l(this, u)), this.then((o) => {
|
|
148
|
-
const c = typeof e == "function" ? e(o) : e, g = { ...typeof t == "function" ? t(o) : t, signal: l(this, d) };
|
|
149
|
-
fetch(c, g).then((y) => n(y)).catch((y) => {
|
|
150
|
-
y.name !== "AbortError" && r(y);
|
|
151
|
-
});
|
|
152
|
-
}), s;
|
|
153
|
-
}
|
|
154
|
-
onCancel(e) {
|
|
155
|
-
let t, n;
|
|
156
|
-
const r = new i((s, o, c) => {
|
|
157
|
-
c.onCancel(e), t = s, n = o;
|
|
158
|
-
}, l(this, d));
|
|
159
|
-
return w(r, u, l(this, u)), this.then(
|
|
160
|
-
(s) => t(s),
|
|
161
|
-
(s) => n(s)
|
|
162
|
-
), r;
|
|
163
|
-
}
|
|
164
|
-
// promisify<TResult1 = T, TResult2 = never>(): Promise<TResult1 | TResult2> {
|
|
165
|
-
// return new Promise((res, rej) => {
|
|
166
|
-
// if (this.#signal.aborted) {
|
|
167
|
-
// this.#clearTimeout();
|
|
168
|
-
// return;
|
|
169
|
-
// } else {
|
|
170
|
-
// this.then(
|
|
171
|
-
// val => res(val),
|
|
172
|
-
// reason => rej(reason)
|
|
173
|
-
// );
|
|
174
|
-
// }
|
|
175
|
-
// });
|
|
176
|
-
// }
|
|
177
|
-
futurizable(e) {
|
|
178
|
-
let t, n;
|
|
179
|
-
const r = new i((s, o) => {
|
|
180
|
-
t = s, n = o;
|
|
181
|
-
}, l(this, d));
|
|
182
|
-
return w(r, u, l(this, u)), this.then((s) => {
|
|
183
|
-
(typeof e == "function" ? e(s) : e).then(t).catch(n);
|
|
184
|
-
}), r;
|
|
185
|
-
}
|
|
186
|
-
static resolve(e, t) {
|
|
187
|
-
return new i((n) => n(e), t);
|
|
188
|
-
}
|
|
189
|
-
static reject(e, t) {
|
|
190
|
-
return new i((n, r) => r(e), t);
|
|
191
|
-
}
|
|
192
|
-
static onCancel({ cb: e, signal: t }) {
|
|
193
|
-
return new i((n, r, s) => {
|
|
194
|
-
s.onCancel(() => n(e()));
|
|
195
|
-
}, t);
|
|
196
|
-
}
|
|
197
|
-
static delay({ cb: e, timer: t, signal: n }) {
|
|
198
|
-
return i.resolve(!0, n).delay(e, t);
|
|
199
|
-
}
|
|
200
|
-
static sleep({ timer: e, signal: t }) {
|
|
201
|
-
return i.delay({
|
|
202
|
-
cb: () => {
|
|
203
|
-
},
|
|
204
|
-
timer: e,
|
|
205
|
-
signal: t
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
static fetch(e, t) {
|
|
209
|
-
const n = (t == null ? void 0 : t.signal) || void 0;
|
|
210
|
-
return t != null && t.signal && delete t.signal, i.resolve(!0, n).fetch(e, t);
|
|
211
|
-
}
|
|
212
|
-
static futurizable({ promise: e, signal: t }) {
|
|
213
|
-
return new i((n, r) => {
|
|
214
|
-
e.then(n).catch(r);
|
|
215
|
-
}, t);
|
|
216
|
-
}
|
|
217
|
-
static all(e, t) {
|
|
218
|
-
var c;
|
|
219
|
-
const { f: n, resolve: r, reject: s, array: o } = j(c = i, v, T).call(c, e, t);
|
|
220
|
-
return super.all(o).then(r).catch(s), n;
|
|
221
|
-
}
|
|
222
|
-
static allSettled(e, t) {
|
|
223
|
-
var c;
|
|
224
|
-
const { f: n, resolve: r, reject: s, array: o } = j(c = i, v, T).call(c, e, t);
|
|
225
|
-
return super.allSettled(o).then(r).catch(s), n;
|
|
226
|
-
}
|
|
227
|
-
static race(e, t) {
|
|
228
|
-
var c;
|
|
229
|
-
const { f: n, resolve: r, reject: s, array: o } = j(c = i, v, T).call(c, e, t);
|
|
230
|
-
return super.race(o).then(r).catch(s), n;
|
|
231
|
-
}
|
|
232
|
-
static any(e, t) {
|
|
233
|
-
var c;
|
|
234
|
-
const { f: n, resolve: r, reject: s, array: o } = j(c = i, v, T).call(c, e, t);
|
|
235
|
-
return super.any(o).then(r).catch(s), n;
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
let x = i;
|
|
239
|
-
u = new WeakMap(), d = new WeakMap(), E = new WeakMap(), z = new WeakSet(), N = function() {
|
|
240
|
-
for (const e of l(this, E))
|
|
241
|
-
clearTimeout(e);
|
|
242
|
-
}, v = new WeakSet(), T = function(e, t) {
|
|
243
|
-
let n, r;
|
|
244
|
-
const s = [], o = new i((c, g, y) => {
|
|
245
|
-
n = c, r = g, y.onCancel(() => {
|
|
246
|
-
for (const b of s)
|
|
247
|
-
b.signal !== t && b.cancel();
|
|
248
|
-
});
|
|
249
|
-
}, t);
|
|
250
|
-
t || (t = o.signal);
|
|
251
|
-
for (const c in e)
|
|
252
|
-
e[c] instanceof i ? s.push(e[c]) : e[c] instanceof Promise ? s.push(new i((g, y) => {
|
|
253
|
-
e[c].then(g).catch(y);
|
|
254
|
-
}, t)) : s.push(i.resolve(e[c]));
|
|
255
|
-
return { f: o, resolve: n, reject: r, array: s };
|
|
256
|
-
}, C(x, v);
|
|
257
|
-
export {
|
|
258
|
-
L as FUTURABLE_STATUS,
|
|
259
|
-
x as Futurable
|
|
260
|
-
};
|