@xylabs/forget 2.11.0 → 2.11.2
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/forget.d.mts +12 -0
- package/dist/forget.d.mts.map +1 -0
- package/dist/forget.js +67 -0
- package/dist/forget.js.map +1 -0
- package/dist/forget.mjs +64 -0
- package/dist/forget.mjs.map +1 -0
- package/dist/index.js +5 -62
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -63
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface ForgetTimeoutConfig {
|
|
2
|
+
cancel: () => void;
|
|
3
|
+
delay: number;
|
|
4
|
+
}
|
|
5
|
+
export 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
|
+
export declare const forget: (promise: Promise<unknown>, timeout?: ForgetTimeoutConfig) => void;
|
|
12
|
+
//# sourceMappingURL=forget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forget.d.ts","sourceRoot":"","sources":["../src/forget.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,IAAI,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;CACd;AAED,qBAAa,aAAa;IACxB,MAAM,CAAC,aAAa,SAAI;IAExB,MAAM,KAAK,MAAM,YAEhB;WAEY,aAAa,CAAC,QAAQ,SAAM,EAAE,OAAO,CAAC,EAAE,MAAM;IAe3D,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,mBAAmB;CAwCvE;AAGD,eAAO,MAAM,MAAM,YAAa,QAAQ,OAAO,CAAC,YAAY,mBAAmB,SAE9E,CAAA"}
|
package/dist/forget.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var delay = require('@xylabs/delay');
|
|
4
|
+
|
|
5
|
+
class ForgetPromise {
|
|
6
|
+
static activeForgets = 0;
|
|
7
|
+
static get active() {
|
|
8
|
+
return this.activeForgets > 0;
|
|
9
|
+
}
|
|
10
|
+
static async awaitInactive(interval = 100, timeout) {
|
|
11
|
+
let timeoutRemaining = timeout;
|
|
12
|
+
while (this.active) {
|
|
13
|
+
await delay.delay(interval);
|
|
14
|
+
if (timeoutRemaining !== undefined) {
|
|
15
|
+
timeoutRemaining -= interval;
|
|
16
|
+
if (timeoutRemaining <= 0) {
|
|
17
|
+
return this.activeForgets;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
//used to explicitly launch an async function (or Promise) with awaiting it
|
|
24
|
+
static forget(promise, timeout) {
|
|
25
|
+
let completed = false;
|
|
26
|
+
this.activeForgets++;
|
|
27
|
+
const promiseWrapper = async () => {
|
|
28
|
+
await promise
|
|
29
|
+
.then(() => {
|
|
30
|
+
this.activeForgets--;
|
|
31
|
+
completed = true;
|
|
32
|
+
})
|
|
33
|
+
.catch(() => {
|
|
34
|
+
this.activeForgets--;
|
|
35
|
+
completed = true;
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
const promises = [promiseWrapper()];
|
|
39
|
+
//if there is a timeout, add it to the race
|
|
40
|
+
if (timeout) {
|
|
41
|
+
const timeoutFunc = async () => {
|
|
42
|
+
await delay.delay(timeout.delay);
|
|
43
|
+
if (!completed) {
|
|
44
|
+
console.log(`forget promise timeout out after ${timeout.delay}ms [Cancelling]`);
|
|
45
|
+
timeout.cancel?.();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
promises.push(timeoutFunc());
|
|
49
|
+
}
|
|
50
|
+
const all = Promise.race(promises);
|
|
51
|
+
all
|
|
52
|
+
.then(() => {
|
|
53
|
+
return;
|
|
54
|
+
})
|
|
55
|
+
.catch(() => {
|
|
56
|
+
return;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
//used to explicitly launch an async function (or Promise) with awaiting it
|
|
61
|
+
const forget = (promise, timeout) => {
|
|
62
|
+
ForgetPromise.forget(promise, timeout);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
exports.ForgetPromise = ForgetPromise;
|
|
66
|
+
exports.forget = forget;
|
|
67
|
+
//# sourceMappingURL=forget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forget.js","sources":["../src/forget.ts"],"sourcesContent":[null],"names":["delay"],"mappings":";;;;AAGQ,MAAQ,aAAI,CAAA;IAClB,OAAO,aAAM,GAAA,CAAA,CAAA;AACd,IAAA,WAAA,MAAA,GAAA;AAED,QAAA,OAAA,IAAA,CAAA,aAA0B,GAAA,CAAA,CAAA;KAClB;IAEN,0BAEC,CAAA,QAAA,GAAA,GAAA,EAAA,OAAA,EAAA;AAEY,QAAA,IAAA,gBAAsB,GAAA,OAAA,CAAA;AAenC,QAAA,OAAO,IAAO,CAAA,MAAS,EAAA;AAwCxB,YAAA,MAAAA,WAAA,CAAA,QAAA,CAAA,CAAA;AAGD,YAAO,IAAA,gBAAyB,KAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/forget.mjs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { delay } from '@xylabs/delay';
|
|
2
|
+
|
|
3
|
+
class ForgetPromise {
|
|
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 !== undefined) {
|
|
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
|
|
27
|
+
.then(() => {
|
|
28
|
+
this.activeForgets--;
|
|
29
|
+
completed = true;
|
|
30
|
+
})
|
|
31
|
+
.catch(() => {
|
|
32
|
+
this.activeForgets--;
|
|
33
|
+
completed = true;
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
const promises = [promiseWrapper()];
|
|
37
|
+
//if there is a timeout, add it to the race
|
|
38
|
+
if (timeout) {
|
|
39
|
+
const timeoutFunc = async () => {
|
|
40
|
+
await delay(timeout.delay);
|
|
41
|
+
if (!completed) {
|
|
42
|
+
console.log(`forget promise timeout out after ${timeout.delay}ms [Cancelling]`);
|
|
43
|
+
timeout.cancel?.();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
promises.push(timeoutFunc());
|
|
47
|
+
}
|
|
48
|
+
const all = Promise.race(promises);
|
|
49
|
+
all
|
|
50
|
+
.then(() => {
|
|
51
|
+
return;
|
|
52
|
+
})
|
|
53
|
+
.catch(() => {
|
|
54
|
+
return;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//used to explicitly launch an async function (or Promise) with awaiting it
|
|
59
|
+
const forget = (promise, timeout) => {
|
|
60
|
+
ForgetPromise.forget(promise, timeout);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export { ForgetPromise, forget };
|
|
64
|
+
//# sourceMappingURL=forget.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forget.mjs","sources":["../src/forget.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAGQ,MAAQ,aAAI,CAAA;IAClB,OAAO,aAAM,GAAA,CAAA,CAAA;AACd,IAAA,WAAA,MAAA,GAAA;AAED,QAAA,OAAA,IAAA,CAAA,aAA0B,GAAA,CAAA,CAAA;KAClB;IAEN,0BAEC,CAAA,QAAA,GAAA,GAAA,EAAA,OAAA,EAAA;AAEY,QAAA,IAAA,gBAAsB,GAAA,OAAA,CAAA;AAenC,QAAA,OAAO,IAAO,CAAA,MAAS,EAAA;AAwCxB,YAAA,MAAA,KAAA,CAAA,QAAA,CAAA,CAAA;AAGD,YAAO,IAAA,gBAAyB,KAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -1,67 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var forget = require('./forget.js');
|
|
4
|
+
require('@xylabs/delay');
|
|
4
5
|
|
|
5
|
-
class ForgetPromise {
|
|
6
|
-
static activeForgets = 0;
|
|
7
|
-
static get active() {
|
|
8
|
-
return this.activeForgets > 0;
|
|
9
|
-
}
|
|
10
|
-
static async awaitInactive(interval = 100, timeout) {
|
|
11
|
-
let timeoutRemaining = timeout;
|
|
12
|
-
while (this.active) {
|
|
13
|
-
await delay.delay(interval);
|
|
14
|
-
if (timeoutRemaining !== undefined) {
|
|
15
|
-
timeoutRemaining -= interval;
|
|
16
|
-
if (timeoutRemaining <= 0) {
|
|
17
|
-
return this.activeForgets;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return 0;
|
|
22
|
-
}
|
|
23
|
-
//used to explicitly launch an async function (or Promise) with awaiting it
|
|
24
|
-
static forget(promise, timeout) {
|
|
25
|
-
let completed = false;
|
|
26
|
-
this.activeForgets++;
|
|
27
|
-
const promiseWrapper = async () => {
|
|
28
|
-
await promise
|
|
29
|
-
.then(() => {
|
|
30
|
-
this.activeForgets--;
|
|
31
|
-
completed = true;
|
|
32
|
-
})
|
|
33
|
-
.catch(() => {
|
|
34
|
-
this.activeForgets--;
|
|
35
|
-
completed = true;
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
const promises = [promiseWrapper()];
|
|
39
|
-
//if there is a timeout, add it to the race
|
|
40
|
-
if (timeout) {
|
|
41
|
-
const timeoutFunc = async () => {
|
|
42
|
-
await delay.delay(timeout.delay);
|
|
43
|
-
if (!completed) {
|
|
44
|
-
console.log(`forget promise timeout out after ${timeout.delay}ms [Cancelling]`);
|
|
45
|
-
timeout.cancel?.();
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
promises.push(timeoutFunc());
|
|
49
|
-
}
|
|
50
|
-
const all = Promise.race(promises);
|
|
51
|
-
all
|
|
52
|
-
.then(() => {
|
|
53
|
-
return;
|
|
54
|
-
})
|
|
55
|
-
.catch(() => {
|
|
56
|
-
return;
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
//used to explicitly launch an async function (or Promise) with awaiting it
|
|
61
|
-
const forget = (promise, timeout) => {
|
|
62
|
-
ForgetPromise.forget(promise, timeout);
|
|
63
|
-
};
|
|
64
6
|
|
|
65
|
-
|
|
66
|
-
exports.
|
|
7
|
+
|
|
8
|
+
exports.ForgetPromise = forget.ForgetPromise;
|
|
9
|
+
exports.forget = forget.forget;
|
|
67
10
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,64 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
class ForgetPromise {
|
|
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 !== undefined) {
|
|
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
|
|
27
|
-
.then(() => {
|
|
28
|
-
this.activeForgets--;
|
|
29
|
-
completed = true;
|
|
30
|
-
})
|
|
31
|
-
.catch(() => {
|
|
32
|
-
this.activeForgets--;
|
|
33
|
-
completed = true;
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
const promises = [promiseWrapper()];
|
|
37
|
-
//if there is a timeout, add it to the race
|
|
38
|
-
if (timeout) {
|
|
39
|
-
const timeoutFunc = async () => {
|
|
40
|
-
await delay(timeout.delay);
|
|
41
|
-
if (!completed) {
|
|
42
|
-
console.log(`forget promise timeout out after ${timeout.delay}ms [Cancelling]`);
|
|
43
|
-
timeout.cancel?.();
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
promises.push(timeoutFunc());
|
|
47
|
-
}
|
|
48
|
-
const all = Promise.race(promises);
|
|
49
|
-
all
|
|
50
|
-
.then(() => {
|
|
51
|
-
return;
|
|
52
|
-
})
|
|
53
|
-
.catch(() => {
|
|
54
|
-
return;
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
//used to explicitly launch an async function (or Promise) with awaiting it
|
|
59
|
-
const forget = (promise, timeout) => {
|
|
60
|
-
ForgetPromise.forget(promise, timeout);
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export { ForgetPromise, forget };
|
|
1
|
+
export { ForgetPromise, forget } from './forget.mjs';
|
|
2
|
+
import '@xylabs/delay';
|
|
64
3
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
package/package.json
CHANGED
|
@@ -48,11 +48,12 @@
|
|
|
48
48
|
"esm"
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@xylabs/delay": "~2.11.
|
|
51
|
+
"@xylabs/delay": "~2.11.2"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@xylabs/ts-scripts-yarn3": "^3.0.0-rc.
|
|
55
|
-
"@xylabs/tsconfig": "^3.0.0-rc.
|
|
54
|
+
"@xylabs/ts-scripts-yarn3": "^3.0.0-rc.27",
|
|
55
|
+
"@xylabs/tsconfig": "^3.0.0-rc.27",
|
|
56
|
+
"typescript": "^5.2.2"
|
|
56
57
|
},
|
|
57
58
|
"publishConfig": {
|
|
58
59
|
"access": "public"
|
|
@@ -62,5 +63,5 @@
|
|
|
62
63
|
"url": "https://github.com/xylabs/sdk-js.git"
|
|
63
64
|
},
|
|
64
65
|
"sideEffects": false,
|
|
65
|
-
"version": "2.11.
|
|
66
|
+
"version": "2.11.2"
|
|
66
67
|
}
|