@augment-vir/common 31.41.0 → 31.42.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,14 @@
|
|
|
1
|
+
import { type MaybePromise } from '@augment-vir/core';
|
|
2
|
+
import { type AnyDuration } from '@date-vir/duration';
|
|
3
|
+
/**
|
|
4
|
+
* Creates an interval that prevents multiple parallel executions. If the previous callback
|
|
5
|
+
* execution is still executing, the next one will not fire.
|
|
6
|
+
*
|
|
7
|
+
* @category Interval
|
|
8
|
+
* @category Package : @augment-vir/common
|
|
9
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
10
|
+
*/
|
|
11
|
+
export declare function createBlockingInterval(callback: () => MaybePromise<void>, interval: AnyDuration): {
|
|
12
|
+
intervalId: NodeJS.Timeout;
|
|
13
|
+
clearInterval(this: void): void;
|
|
14
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { convertDuration } from '@date-vir/duration';
|
|
2
|
+
/**
|
|
3
|
+
* Creates an interval that prevents multiple parallel executions. If the previous callback
|
|
4
|
+
* execution is still executing, the next one will not fire.
|
|
5
|
+
*
|
|
6
|
+
* @category Interval
|
|
7
|
+
* @category Package : @augment-vir/common
|
|
8
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
9
|
+
*/
|
|
10
|
+
export function createBlockingInterval(callback, interval) {
|
|
11
|
+
let isExecuting = false;
|
|
12
|
+
const intervalId = globalThis.setInterval(async () => {
|
|
13
|
+
if (isExecuting) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
isExecuting = true;
|
|
17
|
+
try {
|
|
18
|
+
await callback();
|
|
19
|
+
}
|
|
20
|
+
finally {
|
|
21
|
+
isExecuting = false;
|
|
22
|
+
}
|
|
23
|
+
}, convertDuration(interval, { milliseconds: true }).milliseconds);
|
|
24
|
+
return {
|
|
25
|
+
intervalId,
|
|
26
|
+
clearInterval() {
|
|
27
|
+
globalThis.clearInterval(intervalId);
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export * from './augments/function/execution-duration.js';
|
|
|
22
22
|
export * from './augments/function/if-truthy.js';
|
|
23
23
|
export * from './augments/function/retry.js';
|
|
24
24
|
export * from './augments/function/wrap-in-try.js';
|
|
25
|
+
export * from './augments/interval/blocking-interval.js';
|
|
25
26
|
export * from './augments/json/append-json.js';
|
|
26
27
|
export * from './augments/json/copy-through-json.js';
|
|
27
28
|
export * from './augments/json/json5.js';
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ export * from './augments/function/execution-duration.js';
|
|
|
22
22
|
export * from './augments/function/if-truthy.js';
|
|
23
23
|
export * from './augments/function/retry.js';
|
|
24
24
|
export * from './augments/function/wrap-in-try.js';
|
|
25
|
+
export * from './augments/interval/blocking-interval.js';
|
|
25
26
|
export * from './augments/json/append-json.js';
|
|
26
27
|
export * from './augments/json/copy-through-json.js';
|
|
27
28
|
export * from './augments/json/json5.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/common",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.42.0",
|
|
4
4
|
"description": "A collection of augments, helpers types, functions, and classes for any JavaScript environment.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"augment",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
"test:web": "virmator --no-deps test web"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@augment-vir/assert": "^31.
|
|
44
|
-
"@augment-vir/core": "^31.
|
|
45
|
-
"@date-vir/duration": "^
|
|
43
|
+
"@augment-vir/assert": "^31.42.0",
|
|
44
|
+
"@augment-vir/core": "^31.42.0",
|
|
45
|
+
"@date-vir/duration": "^8.0.0",
|
|
46
46
|
"ansi-styles": "^6.2.3",
|
|
47
47
|
"deepcopy-esm": "^2.1.1",
|
|
48
48
|
"json5": "^2.2.3",
|