@xylabs/forget 2.11.23 → 2.12.0
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/dist/node/{forget.mjs → forget.cjs} +34 -7
- package/dist/node/{forget.mjs.map → forget.cjs.map} +1 -1
- package/dist/node/forget.js +7 -32
- package/dist/node/forget.js.map +1 -1
- package/dist/node/{index.mjs → index.cjs} +36 -7
- package/dist/node/index.cjs.map +1 -0
- package/dist/node/index.js +7 -34
- package/dist/node/index.js.map +1 -1
- package/package.json +7 -9
- package/dist/node/index.mjs.map +0 -1
|
@@ -1,5 +1,30 @@
|
|
|
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
|
+
|
|
1
20
|
// src/forget.ts
|
|
2
|
-
|
|
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");
|
|
3
28
|
var ForgetPromise = class {
|
|
4
29
|
static activeForgets = 0;
|
|
5
30
|
static get active() {
|
|
@@ -8,7 +33,7 @@ var ForgetPromise = class {
|
|
|
8
33
|
static async awaitInactive(interval = 100, timeout) {
|
|
9
34
|
let timeoutRemaining = timeout;
|
|
10
35
|
while (this.active) {
|
|
11
|
-
await delay(interval);
|
|
36
|
+
await (0, import_delay.delay)(interval);
|
|
12
37
|
if (timeoutRemaining !== void 0) {
|
|
13
38
|
timeoutRemaining -= interval;
|
|
14
39
|
if (timeoutRemaining <= 0) {
|
|
@@ -34,10 +59,11 @@ var ForgetPromise = class {
|
|
|
34
59
|
const promises = [promiseWrapper()];
|
|
35
60
|
if (timeout) {
|
|
36
61
|
const timeoutFunc = async () => {
|
|
37
|
-
|
|
62
|
+
var _a;
|
|
63
|
+
await (0, import_delay.delay)(timeout.delay);
|
|
38
64
|
if (!completed) {
|
|
39
65
|
console.log(`forget promise timeout out after ${timeout.delay}ms [Cancelling]`);
|
|
40
|
-
timeout.cancel
|
|
66
|
+
(_a = timeout.cancel) == null ? void 0 : _a.call(timeout);
|
|
41
67
|
}
|
|
42
68
|
};
|
|
43
69
|
promises.push(timeoutFunc());
|
|
@@ -53,8 +79,9 @@ var ForgetPromise = class {
|
|
|
53
79
|
var forget = (promise, timeout) => {
|
|
54
80
|
ForgetPromise.forget(promise, timeout);
|
|
55
81
|
};
|
|
56
|
-
export
|
|
82
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
83
|
+
0 && (module.exports = {
|
|
57
84
|
ForgetPromise,
|
|
58
85
|
forget
|
|
59
|
-
};
|
|
60
|
-
//# sourceMappingURL=forget.
|
|
86
|
+
});
|
|
87
|
+
//# sourceMappingURL=forget.cjs.map
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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
CHANGED
|
@@ -1,30 +1,5 @@
|
|
|
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
1
|
// src/forget.ts
|
|
21
|
-
|
|
22
|
-
__export(forget_exports, {
|
|
23
|
-
ForgetPromise: () => ForgetPromise,
|
|
24
|
-
forget: () => forget
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(forget_exports);
|
|
27
|
-
var import_delay = require("@xylabs/delay");
|
|
2
|
+
import { delay } from "@xylabs/delay";
|
|
28
3
|
var ForgetPromise = class {
|
|
29
4
|
static activeForgets = 0;
|
|
30
5
|
static get active() {
|
|
@@ -33,7 +8,7 @@ var ForgetPromise = class {
|
|
|
33
8
|
static async awaitInactive(interval = 100, timeout) {
|
|
34
9
|
let timeoutRemaining = timeout;
|
|
35
10
|
while (this.active) {
|
|
36
|
-
await
|
|
11
|
+
await delay(interval);
|
|
37
12
|
if (timeoutRemaining !== void 0) {
|
|
38
13
|
timeoutRemaining -= interval;
|
|
39
14
|
if (timeoutRemaining <= 0) {
|
|
@@ -59,10 +34,11 @@ var ForgetPromise = class {
|
|
|
59
34
|
const promises = [promiseWrapper()];
|
|
60
35
|
if (timeout) {
|
|
61
36
|
const timeoutFunc = async () => {
|
|
62
|
-
|
|
37
|
+
var _a;
|
|
38
|
+
await delay(timeout.delay);
|
|
63
39
|
if (!completed) {
|
|
64
40
|
console.log(`forget promise timeout out after ${timeout.delay}ms [Cancelling]`);
|
|
65
|
-
timeout.cancel
|
|
41
|
+
(_a = timeout.cancel) == null ? void 0 : _a.call(timeout);
|
|
66
42
|
}
|
|
67
43
|
};
|
|
68
44
|
promises.push(timeoutFunc());
|
|
@@ -78,9 +54,8 @@ var ForgetPromise = class {
|
|
|
78
54
|
var forget = (promise, timeout) => {
|
|
79
55
|
ForgetPromise.forget(promise, timeout);
|
|
80
56
|
};
|
|
81
|
-
|
|
82
|
-
0 && (module.exports = {
|
|
57
|
+
export {
|
|
83
58
|
ForgetPromise,
|
|
84
59
|
forget
|
|
85
|
-
}
|
|
60
|
+
};
|
|
86
61
|
//# sourceMappingURL=forget.js.map
|
package/dist/node/forget.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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":"
|
|
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":[]}
|
|
@@ -1,5 +1,32 @@
|
|
|
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/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
ForgetPromise: () => ForgetPromise,
|
|
24
|
+
forget: () => forget
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(src_exports);
|
|
27
|
+
|
|
1
28
|
// src/forget.ts
|
|
2
|
-
|
|
29
|
+
var import_delay = require("@xylabs/delay");
|
|
3
30
|
var ForgetPromise = class {
|
|
4
31
|
static activeForgets = 0;
|
|
5
32
|
static get active() {
|
|
@@ -8,7 +35,7 @@ var ForgetPromise = class {
|
|
|
8
35
|
static async awaitInactive(interval = 100, timeout) {
|
|
9
36
|
let timeoutRemaining = timeout;
|
|
10
37
|
while (this.active) {
|
|
11
|
-
await delay(interval);
|
|
38
|
+
await (0, import_delay.delay)(interval);
|
|
12
39
|
if (timeoutRemaining !== void 0) {
|
|
13
40
|
timeoutRemaining -= interval;
|
|
14
41
|
if (timeoutRemaining <= 0) {
|
|
@@ -34,10 +61,11 @@ var ForgetPromise = class {
|
|
|
34
61
|
const promises = [promiseWrapper()];
|
|
35
62
|
if (timeout) {
|
|
36
63
|
const timeoutFunc = async () => {
|
|
37
|
-
|
|
64
|
+
var _a;
|
|
65
|
+
await (0, import_delay.delay)(timeout.delay);
|
|
38
66
|
if (!completed) {
|
|
39
67
|
console.log(`forget promise timeout out after ${timeout.delay}ms [Cancelling]`);
|
|
40
|
-
timeout.cancel
|
|
68
|
+
(_a = timeout.cancel) == null ? void 0 : _a.call(timeout);
|
|
41
69
|
}
|
|
42
70
|
};
|
|
43
71
|
promises.push(timeoutFunc());
|
|
@@ -53,8 +81,9 @@ var ForgetPromise = class {
|
|
|
53
81
|
var forget = (promise, timeout) => {
|
|
54
82
|
ForgetPromise.forget(promise, timeout);
|
|
55
83
|
};
|
|
56
|
-
export
|
|
84
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
+
0 && (module.exports = {
|
|
57
86
|
ForgetPromise,
|
|
58
87
|
forget
|
|
59
|
-
};
|
|
60
|
-
//# sourceMappingURL=index.
|
|
88
|
+
});
|
|
89
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/forget.ts"],"sourcesContent":["import { forget, ForgetPromise } from './forget'\n\nexport { forget, ForgetPromise }\n","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;;;ACAA,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/index.js
CHANGED
|
@@ -1,32 +1,5 @@
|
|
|
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/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
ForgetPromise: () => ForgetPromise,
|
|
24
|
-
forget: () => forget
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(src_exports);
|
|
27
|
-
|
|
28
1
|
// src/forget.ts
|
|
29
|
-
|
|
2
|
+
import { delay } from "@xylabs/delay";
|
|
30
3
|
var ForgetPromise = class {
|
|
31
4
|
static activeForgets = 0;
|
|
32
5
|
static get active() {
|
|
@@ -35,7 +8,7 @@ var ForgetPromise = class {
|
|
|
35
8
|
static async awaitInactive(interval = 100, timeout) {
|
|
36
9
|
let timeoutRemaining = timeout;
|
|
37
10
|
while (this.active) {
|
|
38
|
-
await
|
|
11
|
+
await delay(interval);
|
|
39
12
|
if (timeoutRemaining !== void 0) {
|
|
40
13
|
timeoutRemaining -= interval;
|
|
41
14
|
if (timeoutRemaining <= 0) {
|
|
@@ -61,10 +34,11 @@ var ForgetPromise = class {
|
|
|
61
34
|
const promises = [promiseWrapper()];
|
|
62
35
|
if (timeout) {
|
|
63
36
|
const timeoutFunc = async () => {
|
|
64
|
-
|
|
37
|
+
var _a;
|
|
38
|
+
await delay(timeout.delay);
|
|
65
39
|
if (!completed) {
|
|
66
40
|
console.log(`forget promise timeout out after ${timeout.delay}ms [Cancelling]`);
|
|
67
|
-
timeout.cancel
|
|
41
|
+
(_a = timeout.cancel) == null ? void 0 : _a.call(timeout);
|
|
68
42
|
}
|
|
69
43
|
};
|
|
70
44
|
promises.push(timeoutFunc());
|
|
@@ -80,9 +54,8 @@ var ForgetPromise = class {
|
|
|
80
54
|
var forget = (promise, timeout) => {
|
|
81
55
|
ForgetPromise.forget(promise, timeout);
|
|
82
56
|
};
|
|
83
|
-
|
|
84
|
-
0 && (module.exports = {
|
|
57
|
+
export {
|
|
85
58
|
ForgetPromise,
|
|
86
59
|
forget
|
|
87
|
-
}
|
|
60
|
+
};
|
|
88
61
|
//# sourceMappingURL=index.js.map
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/
|
|
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":[]}
|
package/package.json
CHANGED
|
@@ -12,16 +12,15 @@
|
|
|
12
12
|
},
|
|
13
13
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
14
14
|
"docs": "dist/docs.json",
|
|
15
|
-
"types": "dist/node/index.d.ts",
|
|
16
15
|
"exports": {
|
|
17
16
|
".": {
|
|
18
17
|
"require": {
|
|
19
18
|
"types": "./dist/node/index.d.ts",
|
|
20
|
-
"default": "./dist/node/index.
|
|
19
|
+
"default": "./dist/node/index.cjs"
|
|
21
20
|
},
|
|
22
21
|
"import": {
|
|
23
22
|
"types": "./dist/node/index.d.mts",
|
|
24
|
-
"default": "./dist/node/index.
|
|
23
|
+
"default": "./dist/node/index.js"
|
|
25
24
|
}
|
|
26
25
|
},
|
|
27
26
|
"./docs": {
|
|
@@ -29,8 +28,6 @@
|
|
|
29
28
|
},
|
|
30
29
|
"./package.json": "./package.json"
|
|
31
30
|
},
|
|
32
|
-
"main": "dist/node/index.js",
|
|
33
|
-
"module": "dist/node/index.mjs",
|
|
34
31
|
"homepage": "https://xylabs.com",
|
|
35
32
|
"keywords": [
|
|
36
33
|
"xylabs",
|
|
@@ -39,11 +36,11 @@
|
|
|
39
36
|
"esm"
|
|
40
37
|
],
|
|
41
38
|
"dependencies": {
|
|
42
|
-
"@xylabs/delay": "~2.
|
|
39
|
+
"@xylabs/delay": "~2.12.0"
|
|
43
40
|
},
|
|
44
41
|
"devDependencies": {
|
|
45
|
-
"@xylabs/ts-scripts-yarn3": "^3.0.
|
|
46
|
-
"@xylabs/tsconfig": "^3.0.
|
|
42
|
+
"@xylabs/ts-scripts-yarn3": "^3.0.74",
|
|
43
|
+
"@xylabs/tsconfig": "^3.0.74",
|
|
47
44
|
"typescript": "^5.2.2"
|
|
48
45
|
},
|
|
49
46
|
"publishConfig": {
|
|
@@ -54,5 +51,6 @@
|
|
|
54
51
|
"url": "https://github.com/xylabs/sdk-js.git"
|
|
55
52
|
},
|
|
56
53
|
"sideEffects": false,
|
|
57
|
-
"version": "2.
|
|
54
|
+
"version": "2.12.0",
|
|
55
|
+
"type": "module"
|
|
58
56
|
}
|
package/dist/node/index.mjs.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;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":[]}
|