@xylabs/timer 3.6.11 → 4.0.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/neutral/index.d.ts +4 -2
- package/package.json +7 -14
- package/xy.config.ts +12 -0
- package/dist/browser/index.cjs +0 -73
- package/dist/browser/index.cjs.map +0 -1
- package/dist/browser/index.d.cts +0 -2
- package/dist/browser/index.d.cts.map +0 -1
- package/dist/browser/index.d.mts +0 -2
- package/dist/browser/index.d.mts.map +0 -1
- package/dist/browser/index.d.ts +0 -2
- package/dist/browser/index.d.ts.map +0 -1
- package/dist/browser/index.mjs +0 -50
- package/dist/browser/index.mjs.map +0 -1
- package/dist/browser/setTimeoutEx.d.cts +0 -3
- package/dist/browser/setTimeoutEx.d.cts.map +0 -1
- package/dist/browser/setTimeoutEx.d.mts +0 -3
- package/dist/browser/setTimeoutEx.d.mts.map +0 -1
- package/dist/browser/setTimeoutEx.d.ts +0 -3
- package/dist/browser/setTimeoutEx.d.ts.map +0 -1
- package/dist/neutral/index.cjs +0 -73
- package/dist/neutral/index.cjs.map +0 -1
- package/dist/neutral/index.d.cts +0 -2
- package/dist/neutral/index.d.cts.map +0 -1
- package/dist/neutral/index.d.mts +0 -2
- package/dist/neutral/index.d.mts.map +0 -1
- package/dist/neutral/index.d.ts.map +0 -1
- package/dist/neutral/setTimeoutEx.d.cts +0 -3
- package/dist/neutral/setTimeoutEx.d.cts.map +0 -1
- package/dist/neutral/setTimeoutEx.d.mts +0 -3
- package/dist/neutral/setTimeoutEx.d.mts.map +0 -1
- package/dist/neutral/setTimeoutEx.d.ts +0 -3
- package/dist/neutral/setTimeoutEx.d.ts.map +0 -1
- package/dist/node/index.cjs +0 -78
- package/dist/node/index.cjs.map +0 -1
- package/dist/node/index.d.cts +0 -2
- package/dist/node/index.d.cts.map +0 -1
- package/dist/node/index.d.mts +0 -2
- package/dist/node/index.d.mts.map +0 -1
- package/dist/node/index.d.ts +0 -2
- package/dist/node/index.d.ts.map +0 -1
- package/dist/node/index.mjs +0 -50
- package/dist/node/index.mjs.map +0 -1
- package/dist/node/setTimeoutEx.d.cts +0 -3
- package/dist/node/setTimeoutEx.d.cts.map +0 -1
- package/dist/node/setTimeoutEx.d.mts +0 -3
- package/dist/node/setTimeoutEx.d.mts.map +0 -1
- package/dist/node/setTimeoutEx.d.ts +0 -3
- package/dist/node/setTimeoutEx.d.ts.map +0 -1
package/dist/neutral/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -13,27 +13,20 @@
|
|
|
13
13
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
"default": "./dist/neutral/index.cjs"
|
|
19
|
-
},
|
|
20
|
-
"import": {
|
|
21
|
-
"types": "./dist/neutral/index.d.ts",
|
|
22
|
-
"default": "./dist/neutral/index.mjs"
|
|
23
|
-
}
|
|
16
|
+
"types": "./dist/neutral/index.d.ts",
|
|
17
|
+
"default": "./dist/neutral/index.mjs"
|
|
24
18
|
},
|
|
25
19
|
"./package.json": "./package.json"
|
|
26
20
|
},
|
|
27
|
-
"main": "./dist/neutral/index.cjs",
|
|
28
21
|
"types": "./dist/neutral/index.d.ts",
|
|
29
22
|
"module": "./dist/neutral/index.mjs",
|
|
30
23
|
"dependencies": {
|
|
31
|
-
"@xylabs/assert": "^
|
|
24
|
+
"@xylabs/assert": "^4.0.0"
|
|
32
25
|
},
|
|
33
26
|
"devDependencies": {
|
|
34
|
-
"@types/node": "^22.
|
|
35
|
-
"@xylabs/ts-scripts-yarn3": "^
|
|
36
|
-
"@xylabs/tsconfig": "^
|
|
27
|
+
"@types/node": "^22.2.0",
|
|
28
|
+
"@xylabs/ts-scripts-yarn3": "^4.0.0-rc.15",
|
|
29
|
+
"@xylabs/tsconfig": "^4.0.0-rc.15",
|
|
37
30
|
"typescript": "^5.5.4"
|
|
38
31
|
},
|
|
39
32
|
"engines": {
|
|
@@ -56,6 +49,6 @@
|
|
|
56
49
|
"url": "https://github.com/xylabs/sdk-js.git"
|
|
57
50
|
},
|
|
58
51
|
"sideEffects": false,
|
|
59
|
-
"version": "
|
|
52
|
+
"version": "4.0.0",
|
|
60
53
|
"type": "module"
|
|
61
54
|
}
|
package/xy.config.ts
ADDED
package/dist/browser/index.cjs
DELETED
|
@@ -1,73 +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/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
clearTimeoutEx: () => clearTimeoutEx,
|
|
24
|
-
setTimeoutEx: () => setTimeoutEx
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(src_exports);
|
|
27
|
-
|
|
28
|
-
// src/setTimeoutEx.ts
|
|
29
|
-
var import_assert = require("@xylabs/assert");
|
|
30
|
-
var timeouts = [];
|
|
31
|
-
var currentTimeout;
|
|
32
|
-
var interval = -1;
|
|
33
|
-
var reset = () => {
|
|
34
|
-
interval = -1;
|
|
35
|
-
clearTimeout(currentTimeout);
|
|
36
|
-
currentTimeout = void 0;
|
|
37
|
-
timeouts = [];
|
|
38
|
-
};
|
|
39
|
-
var update = (newTimeouts = timeouts, delayPassed = 0) => {
|
|
40
|
-
if (newTimeouts.length <= 0) {
|
|
41
|
-
reset();
|
|
42
|
-
} else {
|
|
43
|
-
const newInterval = Math.min(...newTimeouts.map((timeout) => timeout.delay));
|
|
44
|
-
if (newInterval === interval && currentTimeout !== void 0) {
|
|
45
|
-
return;
|
|
46
|
-
} else {
|
|
47
|
-
clearTimeout(currentTimeout);
|
|
48
|
-
timeouts = newTimeouts.map((timeout) => ({ delay: timeout.delay - delayPassed, func: timeout.func, id: timeout.id }));
|
|
49
|
-
interval = newInterval;
|
|
50
|
-
currentTimeout = setTimeout(timerFunc, interval);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
var timerFunc = () => {
|
|
55
|
-
const notFiring = timeouts.filter((timeout) => timeout.delay > interval);
|
|
56
|
-
const firing = timeouts.filter((timeout) => timeout.delay <= interval);
|
|
57
|
-
update(notFiring, interval);
|
|
58
|
-
for (const timeout of firing) {
|
|
59
|
-
timeout.func();
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
var setTimeoutEx = (func, delay) => {
|
|
63
|
-
(0, import_assert.assertEx)(delay >= 0, () => "delay must be >= 0");
|
|
64
|
-
const id = `${Date.now()}|${Math.random() * 9999999999}`;
|
|
65
|
-
timeouts.push({ delay, func, id });
|
|
66
|
-
update();
|
|
67
|
-
return id;
|
|
68
|
-
};
|
|
69
|
-
var clearTimeoutEx = (id) => {
|
|
70
|
-
timeouts = timeouts.filter((timeout) => timeout.id !== id);
|
|
71
|
-
update(timeouts);
|
|
72
|
-
};
|
|
73
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/setTimeoutEx.ts"],"sourcesContent":["export * from './setTimeoutEx.ts'\n","import { assertEx } from '@xylabs/assert'\n\ninterface TimeoutInfo {\n delay: number\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n func: Function\n id: string\n}\n\nlet timeouts: TimeoutInfo[] = []\nlet currentTimeout: NodeJS.Timeout | undefined\nlet interval = -1\n\nconst reset = () => {\n interval = -1\n clearTimeout(currentTimeout)\n currentTimeout = undefined\n timeouts = []\n}\n\nconst update = (newTimeouts = timeouts, delayPassed = 0) => {\n // if no more timeouts, set back to initial state\n if (newTimeouts.length <= 0) {\n reset()\n } else {\n const newInterval = Math.min(...newTimeouts.map(timeout => timeout.delay))\n\n if (newInterval === interval && currentTimeout !== undefined) {\n // since nothing changed, just return\n return\n } else {\n clearTimeout(currentTimeout)\n timeouts = newTimeouts.map(timeout => ({ delay: timeout.delay - delayPassed, func: timeout.func, id: timeout.id }))\n // restart timeout since it needs to be different\n interval = newInterval\n currentTimeout = setTimeout(timerFunc, interval)\n }\n }\n}\n\nconst timerFunc = () => {\n const notFiring = timeouts.filter(timeout => timeout.delay > interval)\n const firing = timeouts.filter(timeout => timeout.delay <= interval)\n\n // call this after getting notFiring and firing since set will change in this call\n update(notFiring, interval)\n\n // trigger the ones that need to be triggered\n for (const timeout of firing) {\n timeout.func()\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const setTimeoutEx = (func: Function, delay: number) => {\n assertEx(delay >= 0, () => 'delay must be >= 0')\n const id = `${Date.now()}|${Math.random() * 9_999_999_999}`\n timeouts.push({ delay, func, id })\n update()\n return id\n}\n\nexport const clearTimeoutEx = (id: string) => {\n timeouts = timeouts.filter(timeout => timeout.id !== id)\n update(timeouts)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyB;AASzB,IAAI,WAA0B,CAAC;AAC/B,IAAI;AACJ,IAAI,WAAW;AAEf,IAAM,QAAQ,MAAM;AAClB,aAAW;AACX,eAAa,cAAc;AAC3B,mBAAiB;AACjB,aAAW,CAAC;AACd;AAEA,IAAM,SAAS,CAAC,cAAc,UAAU,cAAc,MAAM;AAE1D,MAAI,YAAY,UAAU,GAAG;AAC3B,UAAM;AAAA,EACR,OAAO;AACL,UAAM,cAAc,KAAK,IAAI,GAAG,YAAY,IAAI,aAAW,QAAQ,KAAK,CAAC;AAEzE,QAAI,gBAAgB,YAAY,mBAAmB,QAAW;AAE5D;AAAA,IACF,OAAO;AACL,mBAAa,cAAc;AAC3B,iBAAW,YAAY,IAAI,cAAY,EAAE,OAAO,QAAQ,QAAQ,aAAa,MAAM,QAAQ,MAAM,IAAI,QAAQ,GAAG,EAAE;AAElH,iBAAW;AACX,uBAAiB,WAAW,WAAW,QAAQ;AAAA,IACjD;AAAA,EACF;AACF;AAEA,IAAM,YAAY,MAAM;AACtB,QAAM,YAAY,SAAS,OAAO,aAAW,QAAQ,QAAQ,QAAQ;AACrE,QAAM,SAAS,SAAS,OAAO,aAAW,QAAQ,SAAS,QAAQ;AAGnE,SAAO,WAAW,QAAQ;AAG1B,aAAW,WAAW,QAAQ;AAC5B,YAAQ,KAAK;AAAA,EACf;AACF;AAGO,IAAM,eAAe,CAAC,MAAgB,UAAkB;AAC7D,8BAAS,SAAS,GAAG,MAAM,oBAAoB;AAC/C,QAAM,KAAK,GAAG,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,UAAa;AACzD,WAAS,KAAK,EAAE,OAAO,MAAM,GAAG,CAAC;AACjC,SAAO;AACP,SAAO;AACT;AAEO,IAAM,iBAAiB,CAAC,OAAe;AAC5C,aAAW,SAAS,OAAO,aAAW,QAAQ,OAAO,EAAE;AACvD,SAAO,QAAQ;AACjB;","names":[]}
|
package/dist/browser/index.d.cts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA"}
|
package/dist/browser/index.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA"}
|
package/dist/browser/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA"}
|
package/dist/browser/index.mjs
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
// src/setTimeoutEx.ts
|
|
2
|
-
import { assertEx } from "@xylabs/assert";
|
|
3
|
-
var timeouts = [];
|
|
4
|
-
var currentTimeout;
|
|
5
|
-
var interval = -1;
|
|
6
|
-
var reset = () => {
|
|
7
|
-
interval = -1;
|
|
8
|
-
clearTimeout(currentTimeout);
|
|
9
|
-
currentTimeout = void 0;
|
|
10
|
-
timeouts = [];
|
|
11
|
-
};
|
|
12
|
-
var update = (newTimeouts = timeouts, delayPassed = 0) => {
|
|
13
|
-
if (newTimeouts.length <= 0) {
|
|
14
|
-
reset();
|
|
15
|
-
} else {
|
|
16
|
-
const newInterval = Math.min(...newTimeouts.map((timeout) => timeout.delay));
|
|
17
|
-
if (newInterval === interval && currentTimeout !== void 0) {
|
|
18
|
-
return;
|
|
19
|
-
} else {
|
|
20
|
-
clearTimeout(currentTimeout);
|
|
21
|
-
timeouts = newTimeouts.map((timeout) => ({ delay: timeout.delay - delayPassed, func: timeout.func, id: timeout.id }));
|
|
22
|
-
interval = newInterval;
|
|
23
|
-
currentTimeout = setTimeout(timerFunc, interval);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
var timerFunc = () => {
|
|
28
|
-
const notFiring = timeouts.filter((timeout) => timeout.delay > interval);
|
|
29
|
-
const firing = timeouts.filter((timeout) => timeout.delay <= interval);
|
|
30
|
-
update(notFiring, interval);
|
|
31
|
-
for (const timeout of firing) {
|
|
32
|
-
timeout.func();
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
var setTimeoutEx = (func, delay) => {
|
|
36
|
-
assertEx(delay >= 0, () => "delay must be >= 0");
|
|
37
|
-
const id = `${Date.now()}|${Math.random() * 9999999999}`;
|
|
38
|
-
timeouts.push({ delay, func, id });
|
|
39
|
-
update();
|
|
40
|
-
return id;
|
|
41
|
-
};
|
|
42
|
-
var clearTimeoutEx = (id) => {
|
|
43
|
-
timeouts = timeouts.filter((timeout) => timeout.id !== id);
|
|
44
|
-
update(timeouts);
|
|
45
|
-
};
|
|
46
|
-
export {
|
|
47
|
-
clearTimeoutEx,
|
|
48
|
-
setTimeoutEx
|
|
49
|
-
};
|
|
50
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/setTimeoutEx.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\n\ninterface TimeoutInfo {\n delay: number\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n func: Function\n id: string\n}\n\nlet timeouts: TimeoutInfo[] = []\nlet currentTimeout: NodeJS.Timeout | undefined\nlet interval = -1\n\nconst reset = () => {\n interval = -1\n clearTimeout(currentTimeout)\n currentTimeout = undefined\n timeouts = []\n}\n\nconst update = (newTimeouts = timeouts, delayPassed = 0) => {\n // if no more timeouts, set back to initial state\n if (newTimeouts.length <= 0) {\n reset()\n } else {\n const newInterval = Math.min(...newTimeouts.map(timeout => timeout.delay))\n\n if (newInterval === interval && currentTimeout !== undefined) {\n // since nothing changed, just return\n return\n } else {\n clearTimeout(currentTimeout)\n timeouts = newTimeouts.map(timeout => ({ delay: timeout.delay - delayPassed, func: timeout.func, id: timeout.id }))\n // restart timeout since it needs to be different\n interval = newInterval\n currentTimeout = setTimeout(timerFunc, interval)\n }\n }\n}\n\nconst timerFunc = () => {\n const notFiring = timeouts.filter(timeout => timeout.delay > interval)\n const firing = timeouts.filter(timeout => timeout.delay <= interval)\n\n // call this after getting notFiring and firing since set will change in this call\n update(notFiring, interval)\n\n // trigger the ones that need to be triggered\n for (const timeout of firing) {\n timeout.func()\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const setTimeoutEx = (func: Function, delay: number) => {\n assertEx(delay >= 0, () => 'delay must be >= 0')\n const id = `${Date.now()}|${Math.random() * 9_999_999_999}`\n timeouts.push({ delay, func, id })\n update()\n return id\n}\n\nexport const clearTimeoutEx = (id: string) => {\n timeouts = timeouts.filter(timeout => timeout.id !== id)\n update(timeouts)\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AASzB,IAAI,WAA0B,CAAC;AAC/B,IAAI;AACJ,IAAI,WAAW;AAEf,IAAM,QAAQ,MAAM;AAClB,aAAW;AACX,eAAa,cAAc;AAC3B,mBAAiB;AACjB,aAAW,CAAC;AACd;AAEA,IAAM,SAAS,CAAC,cAAc,UAAU,cAAc,MAAM;AAE1D,MAAI,YAAY,UAAU,GAAG;AAC3B,UAAM;AAAA,EACR,OAAO;AACL,UAAM,cAAc,KAAK,IAAI,GAAG,YAAY,IAAI,aAAW,QAAQ,KAAK,CAAC;AAEzE,QAAI,gBAAgB,YAAY,mBAAmB,QAAW;AAE5D;AAAA,IACF,OAAO;AACL,mBAAa,cAAc;AAC3B,iBAAW,YAAY,IAAI,cAAY,EAAE,OAAO,QAAQ,QAAQ,aAAa,MAAM,QAAQ,MAAM,IAAI,QAAQ,GAAG,EAAE;AAElH,iBAAW;AACX,uBAAiB,WAAW,WAAW,QAAQ;AAAA,IACjD;AAAA,EACF;AACF;AAEA,IAAM,YAAY,MAAM;AACtB,QAAM,YAAY,SAAS,OAAO,aAAW,QAAQ,QAAQ,QAAQ;AACrE,QAAM,SAAS,SAAS,OAAO,aAAW,QAAQ,SAAS,QAAQ;AAGnE,SAAO,WAAW,QAAQ;AAG1B,aAAW,WAAW,QAAQ;AAC5B,YAAQ,KAAK;AAAA,EACf;AACF;AAGO,IAAM,eAAe,CAAC,MAAgB,UAAkB;AAC7D,WAAS,SAAS,GAAG,MAAM,oBAAoB;AAC/C,QAAM,KAAK,GAAG,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,UAAa;AACzD,WAAS,KAAK,EAAE,OAAO,MAAM,GAAG,CAAC;AACjC,SAAO;AACP,SAAO;AACT;AAEO,IAAM,iBAAiB,CAAC,OAAe;AAC5C,aAAW,SAAS,OAAO,aAAW,QAAQ,OAAO,EAAE;AACvD,SAAO,QAAQ;AACjB;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setTimeoutEx.d.ts","sourceRoot":"","sources":["../../src/setTimeoutEx.ts"],"names":[],"mappings":"AAsDA,eAAO,MAAM,YAAY,SAAU,QAAQ,SAAS,MAAM,WAMzD,CAAA;AAED,eAAO,MAAM,cAAc,OAAQ,MAAM,SAGxC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setTimeoutEx.d.ts","sourceRoot":"","sources":["../../src/setTimeoutEx.ts"],"names":[],"mappings":"AAsDA,eAAO,MAAM,YAAY,SAAU,QAAQ,SAAS,MAAM,WAMzD,CAAA;AAED,eAAO,MAAM,cAAc,OAAQ,MAAM,SAGxC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setTimeoutEx.d.ts","sourceRoot":"","sources":["../../src/setTimeoutEx.ts"],"names":[],"mappings":"AAsDA,eAAO,MAAM,YAAY,SAAU,QAAQ,SAAS,MAAM,WAMzD,CAAA;AAED,eAAO,MAAM,cAAc,OAAQ,MAAM,SAGxC,CAAA"}
|
package/dist/neutral/index.cjs
DELETED
|
@@ -1,73 +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/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
clearTimeoutEx: () => clearTimeoutEx,
|
|
24
|
-
setTimeoutEx: () => setTimeoutEx
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(src_exports);
|
|
27
|
-
|
|
28
|
-
// src/setTimeoutEx.ts
|
|
29
|
-
var import_assert = require("@xylabs/assert");
|
|
30
|
-
var timeouts = [];
|
|
31
|
-
var currentTimeout;
|
|
32
|
-
var interval = -1;
|
|
33
|
-
var reset = () => {
|
|
34
|
-
interval = -1;
|
|
35
|
-
clearTimeout(currentTimeout);
|
|
36
|
-
currentTimeout = void 0;
|
|
37
|
-
timeouts = [];
|
|
38
|
-
};
|
|
39
|
-
var update = (newTimeouts = timeouts, delayPassed = 0) => {
|
|
40
|
-
if (newTimeouts.length <= 0) {
|
|
41
|
-
reset();
|
|
42
|
-
} else {
|
|
43
|
-
const newInterval = Math.min(...newTimeouts.map((timeout) => timeout.delay));
|
|
44
|
-
if (newInterval === interval && currentTimeout !== void 0) {
|
|
45
|
-
return;
|
|
46
|
-
} else {
|
|
47
|
-
clearTimeout(currentTimeout);
|
|
48
|
-
timeouts = newTimeouts.map((timeout) => ({ delay: timeout.delay - delayPassed, func: timeout.func, id: timeout.id }));
|
|
49
|
-
interval = newInterval;
|
|
50
|
-
currentTimeout = setTimeout(timerFunc, interval);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
var timerFunc = () => {
|
|
55
|
-
const notFiring = timeouts.filter((timeout) => timeout.delay > interval);
|
|
56
|
-
const firing = timeouts.filter((timeout) => timeout.delay <= interval);
|
|
57
|
-
update(notFiring, interval);
|
|
58
|
-
for (const timeout of firing) {
|
|
59
|
-
timeout.func();
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
var setTimeoutEx = (func, delay) => {
|
|
63
|
-
(0, import_assert.assertEx)(delay >= 0, () => "delay must be >= 0");
|
|
64
|
-
const id = `${Date.now()}|${Math.random() * 9999999999}`;
|
|
65
|
-
timeouts.push({ delay, func, id });
|
|
66
|
-
update();
|
|
67
|
-
return id;
|
|
68
|
-
};
|
|
69
|
-
var clearTimeoutEx = (id) => {
|
|
70
|
-
timeouts = timeouts.filter((timeout) => timeout.id !== id);
|
|
71
|
-
update(timeouts);
|
|
72
|
-
};
|
|
73
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/setTimeoutEx.ts"],"sourcesContent":["export * from './setTimeoutEx.ts'\n","import { assertEx } from '@xylabs/assert'\n\ninterface TimeoutInfo {\n delay: number\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n func: Function\n id: string\n}\n\nlet timeouts: TimeoutInfo[] = []\nlet currentTimeout: NodeJS.Timeout | undefined\nlet interval = -1\n\nconst reset = () => {\n interval = -1\n clearTimeout(currentTimeout)\n currentTimeout = undefined\n timeouts = []\n}\n\nconst update = (newTimeouts = timeouts, delayPassed = 0) => {\n // if no more timeouts, set back to initial state\n if (newTimeouts.length <= 0) {\n reset()\n } else {\n const newInterval = Math.min(...newTimeouts.map(timeout => timeout.delay))\n\n if (newInterval === interval && currentTimeout !== undefined) {\n // since nothing changed, just return\n return\n } else {\n clearTimeout(currentTimeout)\n timeouts = newTimeouts.map(timeout => ({ delay: timeout.delay - delayPassed, func: timeout.func, id: timeout.id }))\n // restart timeout since it needs to be different\n interval = newInterval\n currentTimeout = setTimeout(timerFunc, interval)\n }\n }\n}\n\nconst timerFunc = () => {\n const notFiring = timeouts.filter(timeout => timeout.delay > interval)\n const firing = timeouts.filter(timeout => timeout.delay <= interval)\n\n // call this after getting notFiring and firing since set will change in this call\n update(notFiring, interval)\n\n // trigger the ones that need to be triggered\n for (const timeout of firing) {\n timeout.func()\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const setTimeoutEx = (func: Function, delay: number) => {\n assertEx(delay >= 0, () => 'delay must be >= 0')\n const id = `${Date.now()}|${Math.random() * 9_999_999_999}`\n timeouts.push({ delay, func, id })\n update()\n return id\n}\n\nexport const clearTimeoutEx = (id: string) => {\n timeouts = timeouts.filter(timeout => timeout.id !== id)\n update(timeouts)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyB;AASzB,IAAI,WAA0B,CAAC;AAC/B,IAAI;AACJ,IAAI,WAAW;AAEf,IAAM,QAAQ,MAAM;AAClB,aAAW;AACX,eAAa,cAAc;AAC3B,mBAAiB;AACjB,aAAW,CAAC;AACd;AAEA,IAAM,SAAS,CAAC,cAAc,UAAU,cAAc,MAAM;AAE1D,MAAI,YAAY,UAAU,GAAG;AAC3B,UAAM;AAAA,EACR,OAAO;AACL,UAAM,cAAc,KAAK,IAAI,GAAG,YAAY,IAAI,aAAW,QAAQ,KAAK,CAAC;AAEzE,QAAI,gBAAgB,YAAY,mBAAmB,QAAW;AAE5D;AAAA,IACF,OAAO;AACL,mBAAa,cAAc;AAC3B,iBAAW,YAAY,IAAI,cAAY,EAAE,OAAO,QAAQ,QAAQ,aAAa,MAAM,QAAQ,MAAM,IAAI,QAAQ,GAAG,EAAE;AAElH,iBAAW;AACX,uBAAiB,WAAW,WAAW,QAAQ;AAAA,IACjD;AAAA,EACF;AACF;AAEA,IAAM,YAAY,MAAM;AACtB,QAAM,YAAY,SAAS,OAAO,aAAW,QAAQ,QAAQ,QAAQ;AACrE,QAAM,SAAS,SAAS,OAAO,aAAW,QAAQ,SAAS,QAAQ;AAGnE,SAAO,WAAW,QAAQ;AAG1B,aAAW,WAAW,QAAQ;AAC5B,YAAQ,KAAK;AAAA,EACf;AACF;AAGO,IAAM,eAAe,CAAC,MAAgB,UAAkB;AAC7D,8BAAS,SAAS,GAAG,MAAM,oBAAoB;AAC/C,QAAM,KAAK,GAAG,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,UAAa;AACzD,WAAS,KAAK,EAAE,OAAO,MAAM,GAAG,CAAC;AACjC,SAAO;AACP,SAAO;AACT;AAEO,IAAM,iBAAiB,CAAC,OAAe;AAC5C,aAAW,SAAS,OAAO,aAAW,QAAQ,OAAO,EAAE;AACvD,SAAO,QAAQ;AACjB;","names":[]}
|
package/dist/neutral/index.d.cts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA"}
|
package/dist/neutral/index.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setTimeoutEx.d.ts","sourceRoot":"","sources":["../../src/setTimeoutEx.ts"],"names":[],"mappings":"AAsDA,eAAO,MAAM,YAAY,SAAU,QAAQ,SAAS,MAAM,WAMzD,CAAA;AAED,eAAO,MAAM,cAAc,OAAQ,MAAM,SAGxC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setTimeoutEx.d.ts","sourceRoot":"","sources":["../../src/setTimeoutEx.ts"],"names":[],"mappings":"AAsDA,eAAO,MAAM,YAAY,SAAU,QAAQ,SAAS,MAAM,WAMzD,CAAA;AAED,eAAO,MAAM,cAAc,OAAQ,MAAM,SAGxC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setTimeoutEx.d.ts","sourceRoot":"","sources":["../../src/setTimeoutEx.ts"],"names":[],"mappings":"AAsDA,eAAO,MAAM,YAAY,SAAU,QAAQ,SAAS,MAAM,WAMzD,CAAA;AAED,eAAO,MAAM,cAAc,OAAQ,MAAM,SAGxC,CAAA"}
|
package/dist/node/index.cjs
DELETED
|
@@ -1,78 +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/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
clearTimeoutEx: () => clearTimeoutEx,
|
|
24
|
-
setTimeoutEx: () => setTimeoutEx
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(src_exports);
|
|
27
|
-
|
|
28
|
-
// src/setTimeoutEx.ts
|
|
29
|
-
var import_assert = require("@xylabs/assert");
|
|
30
|
-
var timeouts = [];
|
|
31
|
-
var currentTimeout;
|
|
32
|
-
var interval = -1;
|
|
33
|
-
var reset = () => {
|
|
34
|
-
interval = -1;
|
|
35
|
-
clearTimeout(currentTimeout);
|
|
36
|
-
currentTimeout = void 0;
|
|
37
|
-
timeouts = [];
|
|
38
|
-
};
|
|
39
|
-
var update = (newTimeouts = timeouts, delayPassed = 0) => {
|
|
40
|
-
if (newTimeouts.length <= 0) {
|
|
41
|
-
reset();
|
|
42
|
-
} else {
|
|
43
|
-
const newInterval = Math.min(...newTimeouts.map((timeout) => timeout.delay));
|
|
44
|
-
if (newInterval === interval && currentTimeout !== void 0) {
|
|
45
|
-
return;
|
|
46
|
-
} else {
|
|
47
|
-
clearTimeout(currentTimeout);
|
|
48
|
-
timeouts = newTimeouts.map((timeout) => ({ delay: timeout.delay - delayPassed, func: timeout.func, id: timeout.id }));
|
|
49
|
-
interval = newInterval;
|
|
50
|
-
currentTimeout = setTimeout(timerFunc, interval);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
var timerFunc = () => {
|
|
55
|
-
const notFiring = timeouts.filter((timeout) => timeout.delay > interval);
|
|
56
|
-
const firing = timeouts.filter((timeout) => timeout.delay <= interval);
|
|
57
|
-
update(notFiring, interval);
|
|
58
|
-
for (const timeout of firing) {
|
|
59
|
-
timeout.func();
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
var setTimeoutEx = (func, delay) => {
|
|
63
|
-
(0, import_assert.assertEx)(delay >= 0, () => "delay must be >= 0");
|
|
64
|
-
const id = `${Date.now()}|${Math.random() * 9999999999}`;
|
|
65
|
-
timeouts.push({ delay, func, id });
|
|
66
|
-
update();
|
|
67
|
-
return id;
|
|
68
|
-
};
|
|
69
|
-
var clearTimeoutEx = (id) => {
|
|
70
|
-
timeouts = timeouts.filter((timeout) => timeout.id !== id);
|
|
71
|
-
update(timeouts);
|
|
72
|
-
};
|
|
73
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
-
0 && (module.exports = {
|
|
75
|
-
clearTimeoutEx,
|
|
76
|
-
setTimeoutEx
|
|
77
|
-
});
|
|
78
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/node/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/setTimeoutEx.ts"],"sourcesContent":["export * from './setTimeoutEx.ts'\n","import { assertEx } from '@xylabs/assert'\n\ninterface TimeoutInfo {\n delay: number\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n func: Function\n id: string\n}\n\nlet timeouts: TimeoutInfo[] = []\nlet currentTimeout: NodeJS.Timeout | undefined\nlet interval = -1\n\nconst reset = () => {\n interval = -1\n clearTimeout(currentTimeout)\n currentTimeout = undefined\n timeouts = []\n}\n\nconst update = (newTimeouts = timeouts, delayPassed = 0) => {\n // if no more timeouts, set back to initial state\n if (newTimeouts.length <= 0) {\n reset()\n } else {\n const newInterval = Math.min(...newTimeouts.map(timeout => timeout.delay))\n\n if (newInterval === interval && currentTimeout !== undefined) {\n // since nothing changed, just return\n return\n } else {\n clearTimeout(currentTimeout)\n timeouts = newTimeouts.map(timeout => ({ delay: timeout.delay - delayPassed, func: timeout.func, id: timeout.id }))\n // restart timeout since it needs to be different\n interval = newInterval\n currentTimeout = setTimeout(timerFunc, interval)\n }\n }\n}\n\nconst timerFunc = () => {\n const notFiring = timeouts.filter(timeout => timeout.delay > interval)\n const firing = timeouts.filter(timeout => timeout.delay <= interval)\n\n // call this after getting notFiring and firing since set will change in this call\n update(notFiring, interval)\n\n // trigger the ones that need to be triggered\n for (const timeout of firing) {\n timeout.func()\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const setTimeoutEx = (func: Function, delay: number) => {\n assertEx(delay >= 0, () => 'delay must be >= 0')\n const id = `${Date.now()}|${Math.random() * 9_999_999_999}`\n timeouts.push({ delay, func, id })\n update()\n return id\n}\n\nexport const clearTimeoutEx = (id: string) => {\n timeouts = timeouts.filter(timeout => timeout.id !== id)\n update(timeouts)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyB;AASzB,IAAI,WAA0B,CAAC;AAC/B,IAAI;AACJ,IAAI,WAAW;AAEf,IAAM,QAAQ,MAAM;AAClB,aAAW;AACX,eAAa,cAAc;AAC3B,mBAAiB;AACjB,aAAW,CAAC;AACd;AAEA,IAAM,SAAS,CAAC,cAAc,UAAU,cAAc,MAAM;AAE1D,MAAI,YAAY,UAAU,GAAG;AAC3B,UAAM;AAAA,EACR,OAAO;AACL,UAAM,cAAc,KAAK,IAAI,GAAG,YAAY,IAAI,aAAW,QAAQ,KAAK,CAAC;AAEzE,QAAI,gBAAgB,YAAY,mBAAmB,QAAW;AAE5D;AAAA,IACF,OAAO;AACL,mBAAa,cAAc;AAC3B,iBAAW,YAAY,IAAI,cAAY,EAAE,OAAO,QAAQ,QAAQ,aAAa,MAAM,QAAQ,MAAM,IAAI,QAAQ,GAAG,EAAE;AAElH,iBAAW;AACX,uBAAiB,WAAW,WAAW,QAAQ;AAAA,IACjD;AAAA,EACF;AACF;AAEA,IAAM,YAAY,MAAM;AACtB,QAAM,YAAY,SAAS,OAAO,aAAW,QAAQ,QAAQ,QAAQ;AACrE,QAAM,SAAS,SAAS,OAAO,aAAW,QAAQ,SAAS,QAAQ;AAGnE,SAAO,WAAW,QAAQ;AAG1B,aAAW,WAAW,QAAQ;AAC5B,YAAQ,KAAK;AAAA,EACf;AACF;AAGO,IAAM,eAAe,CAAC,MAAgB,UAAkB;AAC7D,8BAAS,SAAS,GAAG,MAAM,oBAAoB;AAC/C,QAAM,KAAK,GAAG,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,UAAa;AACzD,WAAS,KAAK,EAAE,OAAO,MAAM,GAAG,CAAC;AACjC,SAAO;AACP,SAAO;AACT;AAEO,IAAM,iBAAiB,CAAC,OAAe;AAC5C,aAAW,SAAS,OAAO,aAAW,QAAQ,OAAO,EAAE;AACvD,SAAO,QAAQ;AACjB;","names":[]}
|
package/dist/node/index.d.cts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA"}
|
package/dist/node/index.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA"}
|
package/dist/node/index.d.ts
DELETED
package/dist/node/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA"}
|
package/dist/node/index.mjs
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
// src/setTimeoutEx.ts
|
|
2
|
-
import { assertEx } from "@xylabs/assert";
|
|
3
|
-
var timeouts = [];
|
|
4
|
-
var currentTimeout;
|
|
5
|
-
var interval = -1;
|
|
6
|
-
var reset = () => {
|
|
7
|
-
interval = -1;
|
|
8
|
-
clearTimeout(currentTimeout);
|
|
9
|
-
currentTimeout = void 0;
|
|
10
|
-
timeouts = [];
|
|
11
|
-
};
|
|
12
|
-
var update = (newTimeouts = timeouts, delayPassed = 0) => {
|
|
13
|
-
if (newTimeouts.length <= 0) {
|
|
14
|
-
reset();
|
|
15
|
-
} else {
|
|
16
|
-
const newInterval = Math.min(...newTimeouts.map((timeout) => timeout.delay));
|
|
17
|
-
if (newInterval === interval && currentTimeout !== void 0) {
|
|
18
|
-
return;
|
|
19
|
-
} else {
|
|
20
|
-
clearTimeout(currentTimeout);
|
|
21
|
-
timeouts = newTimeouts.map((timeout) => ({ delay: timeout.delay - delayPassed, func: timeout.func, id: timeout.id }));
|
|
22
|
-
interval = newInterval;
|
|
23
|
-
currentTimeout = setTimeout(timerFunc, interval);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
var timerFunc = () => {
|
|
28
|
-
const notFiring = timeouts.filter((timeout) => timeout.delay > interval);
|
|
29
|
-
const firing = timeouts.filter((timeout) => timeout.delay <= interval);
|
|
30
|
-
update(notFiring, interval);
|
|
31
|
-
for (const timeout of firing) {
|
|
32
|
-
timeout.func();
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
var setTimeoutEx = (func, delay) => {
|
|
36
|
-
assertEx(delay >= 0, () => "delay must be >= 0");
|
|
37
|
-
const id = `${Date.now()}|${Math.random() * 9999999999}`;
|
|
38
|
-
timeouts.push({ delay, func, id });
|
|
39
|
-
update();
|
|
40
|
-
return id;
|
|
41
|
-
};
|
|
42
|
-
var clearTimeoutEx = (id) => {
|
|
43
|
-
timeouts = timeouts.filter((timeout) => timeout.id !== id);
|
|
44
|
-
update(timeouts);
|
|
45
|
-
};
|
|
46
|
-
export {
|
|
47
|
-
clearTimeoutEx,
|
|
48
|
-
setTimeoutEx
|
|
49
|
-
};
|
|
50
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/node/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/setTimeoutEx.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\n\ninterface TimeoutInfo {\n delay: number\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n func: Function\n id: string\n}\n\nlet timeouts: TimeoutInfo[] = []\nlet currentTimeout: NodeJS.Timeout | undefined\nlet interval = -1\n\nconst reset = () => {\n interval = -1\n clearTimeout(currentTimeout)\n currentTimeout = undefined\n timeouts = []\n}\n\nconst update = (newTimeouts = timeouts, delayPassed = 0) => {\n // if no more timeouts, set back to initial state\n if (newTimeouts.length <= 0) {\n reset()\n } else {\n const newInterval = Math.min(...newTimeouts.map(timeout => timeout.delay))\n\n if (newInterval === interval && currentTimeout !== undefined) {\n // since nothing changed, just return\n return\n } else {\n clearTimeout(currentTimeout)\n timeouts = newTimeouts.map(timeout => ({ delay: timeout.delay - delayPassed, func: timeout.func, id: timeout.id }))\n // restart timeout since it needs to be different\n interval = newInterval\n currentTimeout = setTimeout(timerFunc, interval)\n }\n }\n}\n\nconst timerFunc = () => {\n const notFiring = timeouts.filter(timeout => timeout.delay > interval)\n const firing = timeouts.filter(timeout => timeout.delay <= interval)\n\n // call this after getting notFiring and firing since set will change in this call\n update(notFiring, interval)\n\n // trigger the ones that need to be triggered\n for (const timeout of firing) {\n timeout.func()\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const setTimeoutEx = (func: Function, delay: number) => {\n assertEx(delay >= 0, () => 'delay must be >= 0')\n const id = `${Date.now()}|${Math.random() * 9_999_999_999}`\n timeouts.push({ delay, func, id })\n update()\n return id\n}\n\nexport const clearTimeoutEx = (id: string) => {\n timeouts = timeouts.filter(timeout => timeout.id !== id)\n update(timeouts)\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AASzB,IAAI,WAA0B,CAAC;AAC/B,IAAI;AACJ,IAAI,WAAW;AAEf,IAAM,QAAQ,MAAM;AAClB,aAAW;AACX,eAAa,cAAc;AAC3B,mBAAiB;AACjB,aAAW,CAAC;AACd;AAEA,IAAM,SAAS,CAAC,cAAc,UAAU,cAAc,MAAM;AAE1D,MAAI,YAAY,UAAU,GAAG;AAC3B,UAAM;AAAA,EACR,OAAO;AACL,UAAM,cAAc,KAAK,IAAI,GAAG,YAAY,IAAI,aAAW,QAAQ,KAAK,CAAC;AAEzE,QAAI,gBAAgB,YAAY,mBAAmB,QAAW;AAE5D;AAAA,IACF,OAAO;AACL,mBAAa,cAAc;AAC3B,iBAAW,YAAY,IAAI,cAAY,EAAE,OAAO,QAAQ,QAAQ,aAAa,MAAM,QAAQ,MAAM,IAAI,QAAQ,GAAG,EAAE;AAElH,iBAAW;AACX,uBAAiB,WAAW,WAAW,QAAQ;AAAA,IACjD;AAAA,EACF;AACF;AAEA,IAAM,YAAY,MAAM;AACtB,QAAM,YAAY,SAAS,OAAO,aAAW,QAAQ,QAAQ,QAAQ;AACrE,QAAM,SAAS,SAAS,OAAO,aAAW,QAAQ,SAAS,QAAQ;AAGnE,SAAO,WAAW,QAAQ;AAG1B,aAAW,WAAW,QAAQ;AAC5B,YAAQ,KAAK;AAAA,EACf;AACF;AAGO,IAAM,eAAe,CAAC,MAAgB,UAAkB;AAC7D,WAAS,SAAS,GAAG,MAAM,oBAAoB;AAC/C,QAAM,KAAK,GAAG,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,UAAa;AACzD,WAAS,KAAK,EAAE,OAAO,MAAM,GAAG,CAAC;AACjC,SAAO;AACP,SAAO;AACT;AAEO,IAAM,iBAAiB,CAAC,OAAe;AAC5C,aAAW,SAAS,OAAO,aAAW,QAAQ,OAAO,EAAE;AACvD,SAAO,QAAQ;AACjB;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setTimeoutEx.d.ts","sourceRoot":"","sources":["../../src/setTimeoutEx.ts"],"names":[],"mappings":"AAsDA,eAAO,MAAM,YAAY,SAAU,QAAQ,SAAS,MAAM,WAMzD,CAAA;AAED,eAAO,MAAM,cAAc,OAAQ,MAAM,SAGxC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setTimeoutEx.d.ts","sourceRoot":"","sources":["../../src/setTimeoutEx.ts"],"names":[],"mappings":"AAsDA,eAAO,MAAM,YAAY,SAAU,QAAQ,SAAS,MAAM,WAMzD,CAAA;AAED,eAAO,MAAM,cAAc,OAAQ,MAAM,SAGxC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setTimeoutEx.d.ts","sourceRoot":"","sources":["../../src/setTimeoutEx.ts"],"names":[],"mappings":"AAsDA,eAAO,MAAM,YAAY,SAAU,QAAQ,SAAS,MAAM,WAMzD,CAAA;AAED,eAAO,MAAM,cAAc,OAAQ,MAAM,SAGxC,CAAA"}
|