UNPKG

5 kBJavaScriptView Raw
1var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2 if (kind === "m") throw new TypeError("Private method is not writable");
3 if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4 if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5 return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6};
7var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8 if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9 if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10 return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11};
12var _ExtendablePromise_instances, _ExtendablePromise_values, _ExtendablePromise_promise, _ExtendablePromise_numAdded, _ExtendablePromise_numSettled, _ExtendablePromise_fulfill, _ExtendablePromise_reject, _a;
13// deno-lint-ignore-file no-explicit-any
14import { ResolvablePromise } from '@worker-tools/resolvable-promise';
15// const queueMicrotask = typeof globalThis.queueMicrotask === "function"
16// ? globalThis.queueMicrotask
17// : (callback: VoidFunction) => Promise.resolve().then(callback).catch(e => setTimeout(() => { throw e }));
18export class ExtendablePromise {
19 constructor(f) {
20 _ExtendablePromise_instances.add(this);
21 _ExtendablePromise_values.set(this, []);
22 _ExtendablePromise_promise.set(this, void 0);
23 _ExtendablePromise_numAdded.set(this, 0);
24 _ExtendablePromise_numSettled.set(this, 0);
25 Object.defineProperty(this, _a, {
26 enumerable: true,
27 configurable: true,
28 writable: true,
29 value: 'ExtendablePromise'
30 });
31 // super(_ => _(void 0 as any));
32 __classPrivateFieldSet(this, _ExtendablePromise_promise, new ResolvablePromise(), "f");
33 this.waitUntil(f);
34 // queueMicrotask(() => {
35 // if (this.#numAdded === 0) {
36 // this.#promise.resolve([]);
37 // }
38 // });
39 }
40 waitUntil(f) {
41 var _b;
42 if (f != null) {
43 const i = __classPrivateFieldGet(this, _ExtendablePromise_numAdded, "f");
44 Promise.resolve(f)
45 .then(v => __classPrivateFieldGet(this, _ExtendablePromise_instances, "m", _ExtendablePromise_fulfill).call(this, i, v), r => __classPrivateFieldGet(this, _ExtendablePromise_instances, "m", _ExtendablePromise_reject).call(this, i, r));
46 __classPrivateFieldSet(this, _ExtendablePromise_numAdded, (_b = __classPrivateFieldGet(this, _ExtendablePromise_numAdded, "f"), _b++, _b), "f");
47 }
48 }
49 /** @deprecated Name of this property might change */
50 get settled() { return __classPrivateFieldGet(this, _ExtendablePromise_promise, "f").settled; }
51 then(onfulfilled, onrejected) {
52 return __classPrivateFieldGet(this, _ExtendablePromise_promise, "f").then(onfulfilled, onrejected);
53 }
54 catch(onrejected) {
55 return __classPrivateFieldGet(this, _ExtendablePromise_promise, "f").catch(onrejected);
56 }
57 finally(onfinally) {
58 return __classPrivateFieldGet(this, _ExtendablePromise_promise, "f").finally(onfinally);
59 }
60}
61_ExtendablePromise_values = new WeakMap(), _ExtendablePromise_promise = new WeakMap(), _ExtendablePromise_numAdded = new WeakMap(), _ExtendablePromise_numSettled = new WeakMap(), _ExtendablePromise_instances = new WeakSet(), _ExtendablePromise_fulfill = function _ExtendablePromise_fulfill(i, value) {
62 var _b;
63 __classPrivateFieldGet(this, _ExtendablePromise_values, "f")[i] = { status: 'fulfilled', value };
64 if (__classPrivateFieldSet(this, _ExtendablePromise_numSettled, (_b = __classPrivateFieldGet(this, _ExtendablePromise_numSettled, "f"), ++_b), "f") === __classPrivateFieldGet(this, _ExtendablePromise_numAdded, "f")) {
65 __classPrivateFieldGet(this, _ExtendablePromise_promise, "f").resolve(__classPrivateFieldGet(this, _ExtendablePromise_values, "f"));
66 }
67}, _ExtendablePromise_reject = function _ExtendablePromise_reject(i, reason) {
68 var _b;
69 __classPrivateFieldGet(this, _ExtendablePromise_values, "f")[i] = { status: 'rejected', reason };
70 if (__classPrivateFieldSet(this, _ExtendablePromise_numSettled, (_b = __classPrivateFieldGet(this, _ExtendablePromise_numSettled, "f"), ++_b), "f") === __classPrivateFieldGet(this, _ExtendablePromise_numAdded, "f")) {
71 __classPrivateFieldGet(this, _ExtendablePromise_promise, "f").resolve(__classPrivateFieldGet(this, _ExtendablePromise_values, "f"));
72 }
73}, _a = Symbol.toStringTag;
74//# sourceMappingURL=index.js.map
\No newline at end of file