@xylabs/forget 2.12.21 → 2.12.23
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/package.json +4 -4
- package/dist/browser/forget.cjs +0 -81
- package/dist/browser/forget.cjs.map +0 -1
- package/dist/browser/forget.js +0 -60
- package/dist/browser/forget.js.map +0 -1
- package/dist/node/forget.cjs +0 -87
- package/dist/node/forget.cjs.map +0 -1
- package/dist/node/forget.js +0 -61
- package/dist/node/forget.js.map +0 -1
package/package.json
CHANGED
|
@@ -39,11 +39,11 @@
|
|
|
39
39
|
"esm"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@xylabs/delay": "~2.12.
|
|
42
|
+
"@xylabs/delay": "~2.12.23"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@xylabs/ts-scripts-yarn3": "^3.
|
|
46
|
-
"@xylabs/tsconfig": "^3.
|
|
45
|
+
"@xylabs/ts-scripts-yarn3": "^3.1.1",
|
|
46
|
+
"@xylabs/tsconfig": "^3.1.1",
|
|
47
47
|
"typescript": "^5.2.2"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
@@ -54,6 +54,6 @@
|
|
|
54
54
|
"url": "https://github.com/xylabs/sdk-js.git"
|
|
55
55
|
},
|
|
56
56
|
"sideEffects": false,
|
|
57
|
-
"version": "2.12.
|
|
57
|
+
"version": "2.12.23",
|
|
58
58
|
"type": "module"
|
|
59
59
|
}
|
package/dist/browser/forget.cjs
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/forget.ts
|
|
21
|
-
var forget_exports = {};
|
|
22
|
-
__export(forget_exports, {
|
|
23
|
-
ForgetPromise: () => ForgetPromise,
|
|
24
|
-
forget: () => forget
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(forget_exports);
|
|
27
|
-
var import_delay = require("@xylabs/delay");
|
|
28
|
-
var ForgetPromise = class {
|
|
29
|
-
static activeForgets = 0;
|
|
30
|
-
static get active() {
|
|
31
|
-
return this.activeForgets > 0;
|
|
32
|
-
}
|
|
33
|
-
static async awaitInactive(interval = 100, timeout) {
|
|
34
|
-
let timeoutRemaining = timeout;
|
|
35
|
-
while (this.active) {
|
|
36
|
-
await (0, import_delay.delay)(interval);
|
|
37
|
-
if (timeoutRemaining !== void 0) {
|
|
38
|
-
timeoutRemaining -= interval;
|
|
39
|
-
if (timeoutRemaining <= 0) {
|
|
40
|
-
return this.activeForgets;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return 0;
|
|
45
|
-
}
|
|
46
|
-
//used to explicitly launch an async function (or Promise) with awaiting it
|
|
47
|
-
static forget(promise, timeout) {
|
|
48
|
-
let completed = false;
|
|
49
|
-
this.activeForgets++;
|
|
50
|
-
const promiseWrapper = async () => {
|
|
51
|
-
await promise.then(() => {
|
|
52
|
-
this.activeForgets--;
|
|
53
|
-
completed = true;
|
|
54
|
-
}).catch(() => {
|
|
55
|
-
this.activeForgets--;
|
|
56
|
-
completed = true;
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
const promises = [promiseWrapper()];
|
|
60
|
-
if (timeout) {
|
|
61
|
-
const timeoutFunc = async () => {
|
|
62
|
-
await (0, import_delay.delay)(timeout.delay);
|
|
63
|
-
if (!completed) {
|
|
64
|
-
console.log(`forget promise timeout out after ${timeout.delay}ms [Cancelling]`);
|
|
65
|
-
timeout.cancel?.();
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
promises.push(timeoutFunc());
|
|
69
|
-
}
|
|
70
|
-
const all = Promise.race(promises);
|
|
71
|
-
all.then(() => {
|
|
72
|
-
return;
|
|
73
|
-
}).catch(() => {
|
|
74
|
-
return;
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
var forget = (promise, timeout) => {
|
|
79
|
-
ForgetPromise.forget(promise, timeout);
|
|
80
|
-
};
|
|
81
|
-
//# sourceMappingURL=forget.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/forget.ts"],"sourcesContent":["import { delay } from '@xylabs/delay'\n\nexport interface ForgetTimeoutConfig {\n cancel: () => void\n delay: number\n}\n\nexport class ForgetPromise {\n static activeForgets = 0\n\n static get active() {\n return this.activeForgets > 0\n }\n\n static async awaitInactive(interval = 100, timeout?: number) {\n let timeoutRemaining = timeout\n while (this.active) {\n await delay(interval)\n if (timeoutRemaining !== undefined) {\n timeoutRemaining -= interval\n if (timeoutRemaining <= 0) {\n return this.activeForgets\n }\n }\n }\n return 0\n }\n\n //used to explicitly launch an async function (or Promise) with awaiting it\n static forget(promise: Promise<unknown>, timeout?: ForgetTimeoutConfig) {\n let completed = false\n this.activeForgets++\n\n const promiseWrapper = async () => {\n await promise\n .then(() => {\n this.activeForgets--\n completed = true\n })\n .catch(() => {\n this.activeForgets--\n completed = true\n })\n }\n\n const promises = [promiseWrapper()]\n\n //if there is a timeout, add it to the race\n if (timeout) {\n const timeoutFunc = async () => {\n await delay(timeout.delay)\n if (!completed) {\n console.log(`forget promise timeout out after ${timeout.delay}ms [Cancelling]`)\n timeout.cancel?.()\n }\n }\n promises.push(timeoutFunc())\n }\n\n const all = Promise.race(promises)\n\n all\n .then(() => {\n return\n })\n .catch(() => {\n return\n })\n }\n}\n\n//used to explicitly launch an async function (or Promise) with awaiting it\nexport const forget = (promise: Promise<unknown>, timeout?: ForgetTimeoutConfig) => {\n ForgetPromise.forget(promise, timeout)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsB;AAOf,IAAM,gBAAN,MAAoB;AAAA,EACzB,OAAO,gBAAgB;AAAA,EAEvB,WAAW,SAAS;AAClB,WAAO,KAAK,gBAAgB;AAAA,EAC9B;AAAA,EAEA,aAAa,cAAc,WAAW,KAAK,SAAkB;AAC3D,QAAI,mBAAmB;AACvB,WAAO,KAAK,QAAQ;AAClB,gBAAM,oBAAM,QAAQ;AACpB,UAAI,qBAAqB,QAAW;AAClC,4BAAoB;AACpB,YAAI,oBAAoB,GAAG;AACzB,iBAAO,KAAK;AAAA,QACd;AAAA,MACF;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA;AAAA,EAGA,OAAO,OAAO,SAA2B,SAA+B;AACtE,QAAI,YAAY;AAChB,SAAK;AAEL,UAAM,iBAAiB,YAAY;AACjC,YAAM,QACH,KAAK,MAAM;AACV,aAAK;AACL,oBAAY;AAAA,MACd,CAAC,EACA,MAAM,MAAM;AACX,aAAK;AACL,oBAAY;AAAA,MACd,CAAC;AAAA,IACL;AAEA,UAAM,WAAW,CAAC,eAAe,CAAC;AAGlC,QAAI,SAAS;AACX,YAAM,cAAc,YAAY;AAC9B,kBAAM,oBAAM,QAAQ,KAAK;AACzB,YAAI,CAAC,WAAW;AACd,kBAAQ,IAAI,oCAAoC,QAAQ,KAAK,iBAAiB;AAC9E,kBAAQ,SAAS;AAAA,QACnB;AAAA,MACF;AACA,eAAS,KAAK,YAAY,CAAC;AAAA,IAC7B;AAEA,UAAM,MAAM,QAAQ,KAAK,QAAQ;AAEjC,QACG,KAAK,MAAM;AACV;AAAA,IACF,CAAC,EACA,MAAM,MAAM;AACX;AAAA,IACF,CAAC;AAAA,EACL;AACF;AAGO,IAAM,SAAS,CAAC,SAA2B,YAAkC;AAClF,gBAAc,OAAO,SAAS,OAAO;AACvC;","names":[]}
|
package/dist/browser/forget.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
// src/forget.ts
|
|
2
|
-
import { delay } from "@xylabs/delay";
|
|
3
|
-
var ForgetPromise = class {
|
|
4
|
-
static activeForgets = 0;
|
|
5
|
-
static get active() {
|
|
6
|
-
return this.activeForgets > 0;
|
|
7
|
-
}
|
|
8
|
-
static async awaitInactive(interval = 100, timeout) {
|
|
9
|
-
let timeoutRemaining = timeout;
|
|
10
|
-
while (this.active) {
|
|
11
|
-
await delay(interval);
|
|
12
|
-
if (timeoutRemaining !== void 0) {
|
|
13
|
-
timeoutRemaining -= interval;
|
|
14
|
-
if (timeoutRemaining <= 0) {
|
|
15
|
-
return this.activeForgets;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return 0;
|
|
20
|
-
}
|
|
21
|
-
//used to explicitly launch an async function (or Promise) with awaiting it
|
|
22
|
-
static forget(promise, timeout) {
|
|
23
|
-
let completed = false;
|
|
24
|
-
this.activeForgets++;
|
|
25
|
-
const promiseWrapper = async () => {
|
|
26
|
-
await promise.then(() => {
|
|
27
|
-
this.activeForgets--;
|
|
28
|
-
completed = true;
|
|
29
|
-
}).catch(() => {
|
|
30
|
-
this.activeForgets--;
|
|
31
|
-
completed = true;
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
const promises = [promiseWrapper()];
|
|
35
|
-
if (timeout) {
|
|
36
|
-
const timeoutFunc = async () => {
|
|
37
|
-
await delay(timeout.delay);
|
|
38
|
-
if (!completed) {
|
|
39
|
-
console.log(`forget promise timeout out after ${timeout.delay}ms [Cancelling]`);
|
|
40
|
-
timeout.cancel?.();
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
promises.push(timeoutFunc());
|
|
44
|
-
}
|
|
45
|
-
const all = Promise.race(promises);
|
|
46
|
-
all.then(() => {
|
|
47
|
-
return;
|
|
48
|
-
}).catch(() => {
|
|
49
|
-
return;
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
var forget = (promise, timeout) => {
|
|
54
|
-
ForgetPromise.forget(promise, timeout);
|
|
55
|
-
};
|
|
56
|
-
export {
|
|
57
|
-
ForgetPromise,
|
|
58
|
-
forget
|
|
59
|
-
};
|
|
60
|
-
//# sourceMappingURL=forget.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/forget.ts"],"sourcesContent":["import { delay } from '@xylabs/delay'\n\nexport interface ForgetTimeoutConfig {\n cancel: () => void\n delay: number\n}\n\nexport class ForgetPromise {\n static activeForgets = 0\n\n static get active() {\n return this.activeForgets > 0\n }\n\n static async awaitInactive(interval = 100, timeout?: number) {\n let timeoutRemaining = timeout\n while (this.active) {\n await delay(interval)\n if (timeoutRemaining !== undefined) {\n timeoutRemaining -= interval\n if (timeoutRemaining <= 0) {\n return this.activeForgets\n }\n }\n }\n return 0\n }\n\n //used to explicitly launch an async function (or Promise) with awaiting it\n static forget(promise: Promise<unknown>, timeout?: ForgetTimeoutConfig) {\n let completed = false\n this.activeForgets++\n\n const promiseWrapper = async () => {\n await promise\n .then(() => {\n this.activeForgets--\n completed = true\n })\n .catch(() => {\n this.activeForgets--\n completed = true\n })\n }\n\n const promises = [promiseWrapper()]\n\n //if there is a timeout, add it to the race\n if (timeout) {\n const timeoutFunc = async () => {\n await delay(timeout.delay)\n if (!completed) {\n console.log(`forget promise timeout out after ${timeout.delay}ms [Cancelling]`)\n timeout.cancel?.()\n }\n }\n promises.push(timeoutFunc())\n }\n\n const all = Promise.race(promises)\n\n all\n .then(() => {\n return\n })\n .catch(() => {\n return\n })\n }\n}\n\n//used to explicitly launch an async function (or Promise) with awaiting it\nexport const forget = (promise: Promise<unknown>, timeout?: ForgetTimeoutConfig) => {\n ForgetPromise.forget(promise, timeout)\n}\n"],"mappings":";AAAA,SAAS,aAAa;AAOf,IAAM,gBAAN,MAAoB;AAAA,EACzB,OAAO,gBAAgB;AAAA,EAEvB,WAAW,SAAS;AAClB,WAAO,KAAK,gBAAgB;AAAA,EAC9B;AAAA,EAEA,aAAa,cAAc,WAAW,KAAK,SAAkB;AAC3D,QAAI,mBAAmB;AACvB,WAAO,KAAK,QAAQ;AAClB,YAAM,MAAM,QAAQ;AACpB,UAAI,qBAAqB,QAAW;AAClC,4BAAoB;AACpB,YAAI,oBAAoB,GAAG;AACzB,iBAAO,KAAK;AAAA,QACd;AAAA,MACF;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA;AAAA,EAGA,OAAO,OAAO,SAA2B,SAA+B;AACtE,QAAI,YAAY;AAChB,SAAK;AAEL,UAAM,iBAAiB,YAAY;AACjC,YAAM,QACH,KAAK,MAAM;AACV,aAAK;AACL,oBAAY;AAAA,MACd,CAAC,EACA,MAAM,MAAM;AACX,aAAK;AACL,oBAAY;AAAA,MACd,CAAC;AAAA,IACL;AAEA,UAAM,WAAW,CAAC,eAAe,CAAC;AAGlC,QAAI,SAAS;AACX,YAAM,cAAc,YAAY;AAC9B,cAAM,MAAM,QAAQ,KAAK;AACzB,YAAI,CAAC,WAAW;AACd,kBAAQ,IAAI,oCAAoC,QAAQ,KAAK,iBAAiB;AAC9E,kBAAQ,SAAS;AAAA,QACnB;AAAA,MACF;AACA,eAAS,KAAK,YAAY,CAAC;AAAA,IAC7B;AAEA,UAAM,MAAM,QAAQ,KAAK,QAAQ;AAEjC,QACG,KAAK,MAAM;AACV;AAAA,IACF,CAAC,EACA,MAAM,MAAM;AACX;AAAA,IACF,CAAC;AAAA,EACL;AACF;AAGO,IAAM,SAAS,CAAC,SAA2B,YAAkC;AAClF,gBAAc,OAAO,SAAS,OAAO;AACvC;","names":[]}
|
package/dist/node/forget.cjs
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/forget.ts
|
|
21
|
-
var forget_exports = {};
|
|
22
|
-
__export(forget_exports, {
|
|
23
|
-
ForgetPromise: () => ForgetPromise,
|
|
24
|
-
forget: () => forget
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(forget_exports);
|
|
27
|
-
var import_delay = require("@xylabs/delay");
|
|
28
|
-
var ForgetPromise = class {
|
|
29
|
-
static activeForgets = 0;
|
|
30
|
-
static get active() {
|
|
31
|
-
return this.activeForgets > 0;
|
|
32
|
-
}
|
|
33
|
-
static async awaitInactive(interval = 100, timeout) {
|
|
34
|
-
let timeoutRemaining = timeout;
|
|
35
|
-
while (this.active) {
|
|
36
|
-
await (0, import_delay.delay)(interval);
|
|
37
|
-
if (timeoutRemaining !== void 0) {
|
|
38
|
-
timeoutRemaining -= interval;
|
|
39
|
-
if (timeoutRemaining <= 0) {
|
|
40
|
-
return this.activeForgets;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return 0;
|
|
45
|
-
}
|
|
46
|
-
//used to explicitly launch an async function (or Promise) with awaiting it
|
|
47
|
-
static forget(promise, timeout) {
|
|
48
|
-
let completed = false;
|
|
49
|
-
this.activeForgets++;
|
|
50
|
-
const promiseWrapper = async () => {
|
|
51
|
-
await promise.then(() => {
|
|
52
|
-
this.activeForgets--;
|
|
53
|
-
completed = true;
|
|
54
|
-
}).catch(() => {
|
|
55
|
-
this.activeForgets--;
|
|
56
|
-
completed = true;
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
const promises = [promiseWrapper()];
|
|
60
|
-
if (timeout) {
|
|
61
|
-
const timeoutFunc = async () => {
|
|
62
|
-
var _a;
|
|
63
|
-
await (0, import_delay.delay)(timeout.delay);
|
|
64
|
-
if (!completed) {
|
|
65
|
-
console.log(`forget promise timeout out after ${timeout.delay}ms [Cancelling]`);
|
|
66
|
-
(_a = timeout.cancel) == null ? void 0 : _a.call(timeout);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
promises.push(timeoutFunc());
|
|
70
|
-
}
|
|
71
|
-
const all = Promise.race(promises);
|
|
72
|
-
all.then(() => {
|
|
73
|
-
return;
|
|
74
|
-
}).catch(() => {
|
|
75
|
-
return;
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
var forget = (promise, timeout) => {
|
|
80
|
-
ForgetPromise.forget(promise, timeout);
|
|
81
|
-
};
|
|
82
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
83
|
-
0 && (module.exports = {
|
|
84
|
-
ForgetPromise,
|
|
85
|
-
forget
|
|
86
|
-
});
|
|
87
|
-
//# sourceMappingURL=forget.cjs.map
|
package/dist/node/forget.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/forget.ts"],"sourcesContent":["import { delay } from '@xylabs/delay'\n\nexport interface ForgetTimeoutConfig {\n cancel: () => void\n delay: number\n}\n\nexport class ForgetPromise {\n static activeForgets = 0\n\n static get active() {\n return this.activeForgets > 0\n }\n\n static async awaitInactive(interval = 100, timeout?: number) {\n let timeoutRemaining = timeout\n while (this.active) {\n await delay(interval)\n if (timeoutRemaining !== undefined) {\n timeoutRemaining -= interval\n if (timeoutRemaining <= 0) {\n return this.activeForgets\n }\n }\n }\n return 0\n }\n\n //used to explicitly launch an async function (or Promise) with awaiting it\n static forget(promise: Promise<unknown>, timeout?: ForgetTimeoutConfig) {\n let completed = false\n this.activeForgets++\n\n const promiseWrapper = async () => {\n await promise\n .then(() => {\n this.activeForgets--\n completed = true\n })\n .catch(() => {\n this.activeForgets--\n completed = true\n })\n }\n\n const promises = [promiseWrapper()]\n\n //if there is a timeout, add it to the race\n if (timeout) {\n const timeoutFunc = async () => {\n await delay(timeout.delay)\n if (!completed) {\n console.log(`forget promise timeout out after ${timeout.delay}ms [Cancelling]`)\n timeout.cancel?.()\n }\n }\n promises.push(timeoutFunc())\n }\n\n const all = Promise.race(promises)\n\n all\n .then(() => {\n return\n })\n .catch(() => {\n return\n })\n }\n}\n\n//used to explicitly launch an async function (or Promise) with awaiting it\nexport const forget = (promise: Promise<unknown>, timeout?: ForgetTimeoutConfig) => {\n ForgetPromise.forget(promise, timeout)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsB;AAOf,IAAM,gBAAN,MAAoB;AAAA,EACzB,OAAO,gBAAgB;AAAA,EAEvB,WAAW,SAAS;AAClB,WAAO,KAAK,gBAAgB;AAAA,EAC9B;AAAA,EAEA,aAAa,cAAc,WAAW,KAAK,SAAkB;AAC3D,QAAI,mBAAmB;AACvB,WAAO,KAAK,QAAQ;AAClB,gBAAM,oBAAM,QAAQ;AACpB,UAAI,qBAAqB,QAAW;AAClC,4BAAoB;AACpB,YAAI,oBAAoB,GAAG;AACzB,iBAAO,KAAK;AAAA,QACd;AAAA,MACF;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA;AAAA,EAGA,OAAO,OAAO,SAA2B,SAA+B;AACtE,QAAI,YAAY;AAChB,SAAK;AAEL,UAAM,iBAAiB,YAAY;AACjC,YAAM,QACH,KAAK,MAAM;AACV,aAAK;AACL,oBAAY;AAAA,MACd,CAAC,EACA,MAAM,MAAM;AACX,aAAK;AACL,oBAAY;AAAA,MACd,CAAC;AAAA,IACL;AAEA,UAAM,WAAW,CAAC,eAAe,CAAC;AAGlC,QAAI,SAAS;AACX,YAAM,cAAc,YAAY;AAjDtC;AAkDQ,kBAAM,oBAAM,QAAQ,KAAK;AACzB,YAAI,CAAC,WAAW;AACd,kBAAQ,IAAI,oCAAoC,QAAQ,KAAK,iBAAiB;AAC9E,wBAAQ,WAAR;AAAA,QACF;AAAA,MACF;AACA,eAAS,KAAK,YAAY,CAAC;AAAA,IAC7B;AAEA,UAAM,MAAM,QAAQ,KAAK,QAAQ;AAEjC,QACG,KAAK,MAAM;AACV;AAAA,IACF,CAAC,EACA,MAAM,MAAM;AACX;AAAA,IACF,CAAC;AAAA,EACL;AACF;AAGO,IAAM,SAAS,CAAC,SAA2B,YAAkC;AAClF,gBAAc,OAAO,SAAS,OAAO;AACvC;","names":[]}
|
package/dist/node/forget.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
// src/forget.ts
|
|
2
|
-
import { delay } from "@xylabs/delay";
|
|
3
|
-
var ForgetPromise = class {
|
|
4
|
-
static activeForgets = 0;
|
|
5
|
-
static get active() {
|
|
6
|
-
return this.activeForgets > 0;
|
|
7
|
-
}
|
|
8
|
-
static async awaitInactive(interval = 100, timeout) {
|
|
9
|
-
let timeoutRemaining = timeout;
|
|
10
|
-
while (this.active) {
|
|
11
|
-
await delay(interval);
|
|
12
|
-
if (timeoutRemaining !== void 0) {
|
|
13
|
-
timeoutRemaining -= interval;
|
|
14
|
-
if (timeoutRemaining <= 0) {
|
|
15
|
-
return this.activeForgets;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return 0;
|
|
20
|
-
}
|
|
21
|
-
//used to explicitly launch an async function (or Promise) with awaiting it
|
|
22
|
-
static forget(promise, timeout) {
|
|
23
|
-
let completed = false;
|
|
24
|
-
this.activeForgets++;
|
|
25
|
-
const promiseWrapper = async () => {
|
|
26
|
-
await promise.then(() => {
|
|
27
|
-
this.activeForgets--;
|
|
28
|
-
completed = true;
|
|
29
|
-
}).catch(() => {
|
|
30
|
-
this.activeForgets--;
|
|
31
|
-
completed = true;
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
const promises = [promiseWrapper()];
|
|
35
|
-
if (timeout) {
|
|
36
|
-
const timeoutFunc = async () => {
|
|
37
|
-
var _a;
|
|
38
|
-
await delay(timeout.delay);
|
|
39
|
-
if (!completed) {
|
|
40
|
-
console.log(`forget promise timeout out after ${timeout.delay}ms [Cancelling]`);
|
|
41
|
-
(_a = timeout.cancel) == null ? void 0 : _a.call(timeout);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
promises.push(timeoutFunc());
|
|
45
|
-
}
|
|
46
|
-
const all = Promise.race(promises);
|
|
47
|
-
all.then(() => {
|
|
48
|
-
return;
|
|
49
|
-
}).catch(() => {
|
|
50
|
-
return;
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
var forget = (promise, timeout) => {
|
|
55
|
-
ForgetPromise.forget(promise, timeout);
|
|
56
|
-
};
|
|
57
|
-
export {
|
|
58
|
-
ForgetPromise,
|
|
59
|
-
forget
|
|
60
|
-
};
|
|
61
|
-
//# sourceMappingURL=forget.js.map
|
package/dist/node/forget.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/forget.ts"],"sourcesContent":["import { delay } from '@xylabs/delay'\n\nexport interface ForgetTimeoutConfig {\n cancel: () => void\n delay: number\n}\n\nexport class ForgetPromise {\n static activeForgets = 0\n\n static get active() {\n return this.activeForgets > 0\n }\n\n static async awaitInactive(interval = 100, timeout?: number) {\n let timeoutRemaining = timeout\n while (this.active) {\n await delay(interval)\n if (timeoutRemaining !== undefined) {\n timeoutRemaining -= interval\n if (timeoutRemaining <= 0) {\n return this.activeForgets\n }\n }\n }\n return 0\n }\n\n //used to explicitly launch an async function (or Promise) with awaiting it\n static forget(promise: Promise<unknown>, timeout?: ForgetTimeoutConfig) {\n let completed = false\n this.activeForgets++\n\n const promiseWrapper = async () => {\n await promise\n .then(() => {\n this.activeForgets--\n completed = true\n })\n .catch(() => {\n this.activeForgets--\n completed = true\n })\n }\n\n const promises = [promiseWrapper()]\n\n //if there is a timeout, add it to the race\n if (timeout) {\n const timeoutFunc = async () => {\n await delay(timeout.delay)\n if (!completed) {\n console.log(`forget promise timeout out after ${timeout.delay}ms [Cancelling]`)\n timeout.cancel?.()\n }\n }\n promises.push(timeoutFunc())\n }\n\n const all = Promise.race(promises)\n\n all\n .then(() => {\n return\n })\n .catch(() => {\n return\n })\n }\n}\n\n//used to explicitly launch an async function (or Promise) with awaiting it\nexport const forget = (promise: Promise<unknown>, timeout?: ForgetTimeoutConfig) => {\n ForgetPromise.forget(promise, timeout)\n}\n"],"mappings":";AAAA,SAAS,aAAa;AAOf,IAAM,gBAAN,MAAoB;AAAA,EACzB,OAAO,gBAAgB;AAAA,EAEvB,WAAW,SAAS;AAClB,WAAO,KAAK,gBAAgB;AAAA,EAC9B;AAAA,EAEA,aAAa,cAAc,WAAW,KAAK,SAAkB;AAC3D,QAAI,mBAAmB;AACvB,WAAO,KAAK,QAAQ;AAClB,YAAM,MAAM,QAAQ;AACpB,UAAI,qBAAqB,QAAW;AAClC,4BAAoB;AACpB,YAAI,oBAAoB,GAAG;AACzB,iBAAO,KAAK;AAAA,QACd;AAAA,MACF;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA;AAAA,EAGA,OAAO,OAAO,SAA2B,SAA+B;AACtE,QAAI,YAAY;AAChB,SAAK;AAEL,UAAM,iBAAiB,YAAY;AACjC,YAAM,QACH,KAAK,MAAM;AACV,aAAK;AACL,oBAAY;AAAA,MACd,CAAC,EACA,MAAM,MAAM;AACX,aAAK;AACL,oBAAY;AAAA,MACd,CAAC;AAAA,IACL;AAEA,UAAM,WAAW,CAAC,eAAe,CAAC;AAGlC,QAAI,SAAS;AACX,YAAM,cAAc,YAAY;AAjDtC;AAkDQ,cAAM,MAAM,QAAQ,KAAK;AACzB,YAAI,CAAC,WAAW;AACd,kBAAQ,IAAI,oCAAoC,QAAQ,KAAK,iBAAiB;AAC9E,wBAAQ,WAAR;AAAA,QACF;AAAA,MACF;AACA,eAAS,KAAK,YAAY,CAAC;AAAA,IAC7B;AAEA,UAAM,MAAM,QAAQ,KAAK,QAAQ;AAEjC,QACG,KAAK,MAAM;AACV;AAAA,IACF,CAAC,EACA,MAAM,MAAM;AACX;AAAA,IACF,CAAC;AAAA,EACL;AACF;AAGO,IAAM,SAAS,CAAC,SAA2B,YAAkC;AAClF,gBAAc,OAAO,SAAS,OAAO;AACvC;","names":[]}
|