@xylabs/forget 2.9.2 → 2.10.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.
@@ -0,0 +1,13 @@
1
+ interface ForgetTimeoutConfig {
2
+ cancel: () => void;
3
+ delay: number;
4
+ }
5
+ declare class ForgetPromise {
6
+ static activeForgets: number;
7
+ static get active(): boolean;
8
+ static awaitInactive(interval?: number, timeout?: number): Promise<number>;
9
+ static forget(promise: Promise<unknown>, timeout?: ForgetTimeoutConfig): void;
10
+ }
11
+ declare const forget: (promise: Promise<unknown>, timeout?: ForgetTimeoutConfig) => void;
12
+
13
+ export { ForgetPromise, ForgetTimeoutConfig, forget };
@@ -1,12 +1,13 @@
1
- export interface ForgetTimeoutConfig {
1
+ interface ForgetTimeoutConfig {
2
2
  cancel: () => void;
3
3
  delay: number;
4
4
  }
5
- export declare class ForgetPromise {
5
+ declare class ForgetPromise {
6
6
  static activeForgets: number;
7
7
  static get active(): boolean;
8
8
  static awaitInactive(interval?: number, timeout?: number): Promise<number>;
9
9
  static forget(promise: Promise<unknown>, timeout?: ForgetTimeoutConfig): void;
10
10
  }
11
- export declare const forget: (promise: Promise<unknown>, timeout?: ForgetTimeoutConfig) => void;
12
- //# sourceMappingURL=forget.d.ts.map
11
+ declare const forget: (promise: Promise<unknown>, timeout?: ForgetTimeoutConfig) => void;
12
+
13
+ export { ForgetPromise, ForgetTimeoutConfig, forget };
package/dist/forget.js ADDED
@@ -0,0 +1,86 @@
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
+ // Annotate the CommonJS export names for ESM import in node:
82
+ 0 && (module.exports = {
83
+ ForgetPromise,
84
+ forget
85
+ });
86
+ //# sourceMappingURL=forget.js.map
@@ -0,0 +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;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":[]}
@@ -0,0 +1,60 @@
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.mjs.map
@@ -0,0 +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,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":[]}
@@ -0,0 +1,6 @@
1
+ import { forget } from './forget.mjs';
2
+ export { ForgetPromise } from './forget.mjs';
3
+
4
+
5
+
6
+ export { forget as default, forget };
@@ -0,0 +1,6 @@
1
+ import { forget } from './forget.js';
2
+ export { ForgetPromise } from './forget.js';
3
+
4
+
5
+
6
+ export { forget as default, forget };
package/dist/index.js ADDED
@@ -0,0 +1,92 @@
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
+ default: () => src_default,
25
+ forget: () => forget
26
+ });
27
+ module.exports = __toCommonJS(src_exports);
28
+
29
+ // src/forget.ts
30
+ var import_delay = require("@xylabs/delay");
31
+ var ForgetPromise = class {
32
+ static activeForgets = 0;
33
+ static get active() {
34
+ return this.activeForgets > 0;
35
+ }
36
+ static async awaitInactive(interval = 100, timeout) {
37
+ let timeoutRemaining = timeout;
38
+ while (this.active) {
39
+ await (0, import_delay.delay)(interval);
40
+ if (timeoutRemaining !== void 0) {
41
+ timeoutRemaining -= interval;
42
+ if (timeoutRemaining <= 0) {
43
+ return this.activeForgets;
44
+ }
45
+ }
46
+ }
47
+ return 0;
48
+ }
49
+ //used to explicitly launch an async function (or Promise) with awaiting it
50
+ static forget(promise, timeout) {
51
+ let completed = false;
52
+ this.activeForgets++;
53
+ const promiseWrapper = async () => {
54
+ await promise.then(() => {
55
+ this.activeForgets--;
56
+ completed = true;
57
+ }).catch(() => {
58
+ this.activeForgets--;
59
+ completed = true;
60
+ });
61
+ };
62
+ const promises = [promiseWrapper()];
63
+ if (timeout) {
64
+ const timeoutFunc = async () => {
65
+ await (0, import_delay.delay)(timeout.delay);
66
+ if (!completed) {
67
+ console.log(`forget promise timeout out after ${timeout.delay}ms [Cancelling]`);
68
+ timeout.cancel?.();
69
+ }
70
+ };
71
+ promises.push(timeoutFunc());
72
+ }
73
+ const all = Promise.race(promises);
74
+ all.then(() => {
75
+ return;
76
+ }).catch(() => {
77
+ return;
78
+ });
79
+ }
80
+ };
81
+ var forget = (promise, timeout) => {
82
+ ForgetPromise.forget(promise, timeout);
83
+ };
84
+
85
+ // src/index.ts
86
+ var src_default = forget;
87
+ // Annotate the CommonJS export names for ESM import in node:
88
+ 0 && (module.exports = {
89
+ ForgetPromise,
90
+ forget
91
+ });
92
+ //# sourceMappingURL=index.js.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\n// eslint-disable-next-line import/no-default-export\nexport default forget\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;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;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;;;ADrEA,IAAO,cAAQ;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,64 @@
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
+
57
+ // src/index.ts
58
+ var src_default = forget;
59
+ export {
60
+ ForgetPromise,
61
+ src_default as default,
62
+ forget
63
+ };
64
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/forget.ts","../src/index.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","import { forget, ForgetPromise } from './forget'\n\nexport { forget, ForgetPromise }\n\n// eslint-disable-next-line import/no-default-export\nexport default forget\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;;;ACrEA,IAAO,cAAQ;","names":[]}
package/package.json CHANGED
@@ -11,28 +11,39 @@
11
11
  "url": "https://github.com/xylabs/sdk-js/issues"
12
12
  },
13
13
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
14
- "browser": "dist/esm/index.js",
15
- "main": "dist/cjs/index.js",
16
- "module": "dist/esm/index.js",
17
14
  "docs": "dist/docs.json",
18
- "types": "dist/types/index.d.ts",
15
+ "types": "dist/index.d.ts",
19
16
  "exports": {
20
17
  ".": {
21
- "node": {
22
- "import": "./dist/esm/index.js",
23
- "require": "./dist/cjs/index.js"
18
+ "require": {
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/index.js"
24
21
  },
25
- "browser": {
26
- "import": "./dist/esm/index.js",
27
- "require": "./dist/cjs/index.js"
28
- },
29
- "default": "./dist/esm/index.js"
22
+ "import": {
23
+ "types": "./dist/index.d.mts",
24
+ "default": "./dist/index.mjs"
25
+ }
30
26
  },
31
27
  "./dist/docs.json": {
32
28
  "default": "./dist/docs.json"
33
29
  },
30
+ "./cjs": {
31
+ "default": "./dist/index.js"
32
+ },
33
+ "./docs": {
34
+ "default": "./dist/docs.json"
35
+ },
36
+ "./esm": {
37
+ "default": "./dist/index.mjs"
38
+ },
34
39
  "./package.json": "./package.json"
35
40
  },
41
+ "main": "dist/index.js",
42
+ "module": "dist/index.mjs",
43
+ "scripts": {
44
+ "package-compile": "tsup && publint",
45
+ "package-recompile": "tsup && publint"
46
+ },
36
47
  "homepage": "https://xylabs.com",
37
48
  "keywords": [
38
49
  "xylabs",
@@ -41,11 +52,13 @@
41
52
  "esm"
42
53
  ],
43
54
  "dependencies": {
44
- "@xylabs/delay": "^2.9.2"
55
+ "@xylabs/delay": "~2.10.0"
45
56
  },
46
57
  "devDependencies": {
47
- "@xylabs/ts-scripts-yarn3": "^2.17.17",
48
- "@xylabs/tsconfig": "^2.17.17"
58
+ "@xylabs/ts-scripts-yarn3": "^2.19.5",
59
+ "@xylabs/tsconfig": "^2.19.5",
60
+ "publint": "^0.2.2",
61
+ "tsup": "^7.2.0"
49
62
  },
50
63
  "publishConfig": {
51
64
  "access": "public"
@@ -55,5 +68,5 @@
55
68
  "url": "https://github.com/xylabs/sdk-js.git"
56
69
  },
57
70
  "sideEffects": false,
58
- "version": "2.9.2"
71
+ "version": "2.10.0"
59
72
  }
package/tsup.config.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { defineConfig } from 'tsup'
2
+
3
+ // eslint-disable-next-line import/no-default-export
4
+ export default defineConfig({
5
+ bundle: true,
6
+ cjsInterop: true,
7
+ clean: true,
8
+ dts: true,
9
+ entry: ['src'],
10
+ format: ['cjs', 'esm'],
11
+ sourcemap: true,
12
+ splitting: false,
13
+ tsconfig: 'tsconfig.json',
14
+ })
@@ -1,70 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.forget = exports.ForgetPromise = void 0;
4
- const tslib_1 = require("tslib");
5
- const delay_1 = require("@xylabs/delay");
6
- class ForgetPromise {
7
- static get active() {
8
- return this.activeForgets > 0;
9
- }
10
- static awaitInactive(interval = 100, timeout) {
11
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
12
- let timeoutRemaining = timeout;
13
- while (this.active) {
14
- yield (0, delay_1.delay)(interval);
15
- if (timeoutRemaining !== undefined) {
16
- timeoutRemaining -= interval;
17
- if (timeoutRemaining <= 0) {
18
- return this.activeForgets;
19
- }
20
- }
21
- }
22
- return 0;
23
- });
24
- }
25
- //used to explicitly launch an async function (or Promise) with awaiting it
26
- static forget(promise, timeout) {
27
- let completed = false;
28
- this.activeForgets++;
29
- const promiseWrapper = () => tslib_1.__awaiter(this, void 0, void 0, function* () {
30
- yield promise
31
- .then(() => {
32
- this.activeForgets--;
33
- completed = true;
34
- })
35
- .catch(() => {
36
- this.activeForgets--;
37
- completed = true;
38
- });
39
- });
40
- const promises = [promiseWrapper()];
41
- //if there is a timeout, add it to the race
42
- if (timeout) {
43
- const timeoutFunc = () => tslib_1.__awaiter(this, void 0, void 0, function* () {
44
- var _a;
45
- yield (0, delay_1.delay)(timeout.delay);
46
- if (!completed) {
47
- console.log(`forget promise timeout out after ${timeout.delay}ms [Cancelling]`);
48
- (_a = timeout.cancel) === null || _a === void 0 ? void 0 : _a.call(timeout);
49
- }
50
- });
51
- promises.push(timeoutFunc());
52
- }
53
- const all = Promise.race(promises);
54
- all
55
- .then(() => {
56
- return;
57
- })
58
- .catch(() => {
59
- return;
60
- });
61
- }
62
- }
63
- exports.ForgetPromise = ForgetPromise;
64
- ForgetPromise.activeForgets = 0;
65
- //used to explicitly launch an async function (or Promise) with awaiting it
66
- const forget = (promise, timeout) => {
67
- ForgetPromise.forget(promise, timeout);
68
- };
69
- exports.forget = forget;
70
- //# sourceMappingURL=forget.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"forget.js","sourceRoot":"","sources":["../../src/forget.ts"],"names":[],"mappings":";;;;AAAA,yCAAqC;AAOrC,MAAa,aAAa;IAGxB,MAAM,KAAK,MAAM;QACf,OAAO,IAAI,CAAC,aAAa,GAAG,CAAC,CAAA;IAC/B,CAAC;IAED,MAAM,CAAO,aAAa,CAAC,QAAQ,GAAG,GAAG,EAAE,OAAgB;;YACzD,IAAI,gBAAgB,GAAG,OAAO,CAAA;YAC9B,OAAO,IAAI,CAAC,MAAM,EAAE;gBAClB,MAAM,IAAA,aAAK,EAAC,QAAQ,CAAC,CAAA;gBACrB,IAAI,gBAAgB,KAAK,SAAS,EAAE;oBAClC,gBAAgB,IAAI,QAAQ,CAAA;oBAC5B,IAAI,gBAAgB,IAAI,CAAC,EAAE;wBACzB,OAAO,IAAI,CAAC,aAAa,CAAA;qBAC1B;iBACF;aACF;YACD,OAAO,CAAC,CAAA;QACV,CAAC;KAAA;IAED,2EAA2E;IAC3E,MAAM,CAAC,MAAM,CAAC,OAAyB,EAAE,OAA6B;QACpE,IAAI,SAAS,GAAG,KAAK,CAAA;QACrB,IAAI,CAAC,aAAa,EAAE,CAAA;QAEpB,MAAM,cAAc,GAAG,GAAS,EAAE;YAChC,MAAM,OAAO;iBACV,IAAI,CAAC,GAAG,EAAE;gBACT,IAAI,CAAC,aAAa,EAAE,CAAA;gBACpB,SAAS,GAAG,IAAI,CAAA;YAClB,CAAC,CAAC;iBACD,KAAK,CAAC,GAAG,EAAE;gBACV,IAAI,CAAC,aAAa,EAAE,CAAA;gBACpB,SAAS,GAAG,IAAI,CAAA;YAClB,CAAC,CAAC,CAAA;QACN,CAAC,CAAA,CAAA;QAED,MAAM,QAAQ,GAAG,CAAC,cAAc,EAAE,CAAC,CAAA;QAEnC,2CAA2C;QAC3C,IAAI,OAAO,EAAE;YACX,MAAM,WAAW,GAAG,GAAS,EAAE;;gBAC7B,MAAM,IAAA,aAAK,EAAC,OAAO,CAAC,KAAK,CAAC,CAAA;gBAC1B,IAAI,CAAC,SAAS,EAAE;oBACd,OAAO,CAAC,GAAG,CAAC,oCAAoC,OAAO,CAAC,KAAK,iBAAiB,CAAC,CAAA;oBAC/E,MAAA,OAAO,CAAC,MAAM,uDAAI,CAAA;iBACnB;YACH,CAAC,CAAA,CAAA;YACD,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAA;SAC7B;QAED,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAElC,GAAG;aACA,IAAI,CAAC,GAAG,EAAE;YACT,OAAM;QACR,CAAC,CAAC;aACD,KAAK,CAAC,GAAG,EAAE;YACV,OAAM;QACR,CAAC,CAAC,CAAA;IACN,CAAC;;AA7DH,sCA8DC;AA7DQ,2BAAa,GAAG,CAAC,CAAA;AA+D1B,2EAA2E;AACpE,MAAM,MAAM,GAAG,CAAC,OAAyB,EAAE,OAA6B,EAAE,EAAE;IACjF,aAAa,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;AACxC,CAAC,CAAA;AAFY,QAAA,MAAM,UAElB"}
package/dist/cjs/index.js DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ForgetPromise = exports.forget = void 0;
4
- const forget_1 = require("./forget");
5
- Object.defineProperty(exports, "forget", { enumerable: true, get: function () { return forget_1.forget; } });
6
- Object.defineProperty(exports, "ForgetPromise", { enumerable: true, get: function () { return forget_1.ForgetPromise; } });
7
- // eslint-disable-next-line import/no-default-export
8
- exports.default = forget_1.forget;
9
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAAgD;AAEvC,uFAFA,eAAM,OAEA;AAAE,8FAFA,sBAAa,OAEA;AAE9B,oDAAoD;AACpD,kBAAe,eAAM,CAAA"}