@sohanemon/utils 5.1.6 → 5.1.8
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/functions/index.js
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type Task = () => Promise<void> | void;
|
|
2
|
+
interface ScheduleOpts {
|
|
3
|
+
retry?: number;
|
|
4
|
+
delay?: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Runs a function asynchronously in the background.
|
|
8
|
+
* Returns immediately, retries on failure if configured.
|
|
9
|
+
* Logs total time taken.
|
|
10
|
+
*/
|
|
11
|
+
export declare function schedule(task: Task, options?: ScheduleOpts): void;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs a function asynchronously in the background.
|
|
3
|
+
* Returns immediately, retries on failure if configured.
|
|
4
|
+
* Logs total time taken.
|
|
5
|
+
*/
|
|
6
|
+
export function schedule(task, options = {}) {
|
|
7
|
+
const { retry = 0, delay = 0 } = options;
|
|
8
|
+
const start = Date.now();
|
|
9
|
+
const attempt = async (triesLeft) => {
|
|
10
|
+
try {
|
|
11
|
+
await task();
|
|
12
|
+
const total = Date.now() - start;
|
|
13
|
+
console.log(`⚡[schedule.ts] Completed in ${total}ms`);
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
console.log('⚡[schedule.ts] err:', err);
|
|
17
|
+
if (triesLeft > 0) {
|
|
18
|
+
console.log(`⚡[schedule.ts] Retrying in ${delay}ms...`);
|
|
19
|
+
setTimeout(() => attempt(triesLeft - 1), delay);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
const total = Date.now() - start;
|
|
23
|
+
console.log(`⚡[schedule.ts] Failed after ${total}ms`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
// Schedule immediately
|
|
28
|
+
setTimeout(() => attempt(retry), 0);
|
|
29
|
+
}
|
package/dist/types/gates.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type IMPLIES<T, U> = T extends U ? true : false;
|
|
|
4
4
|
export type XOR_Binary<T, U> = T | U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
|
|
5
5
|
export type XNOR_Binary<T, U> = (T & U) | (Without<T, U> & Without<U, T>);
|
|
6
6
|
/**
|
|
7
|
-
* Computes a type-level AND for a tuple of types.
|
|
7
|
+
* Computes a type-level AND (all must true) for a tuple of types.
|
|
8
8
|
*
|
|
9
9
|
* Truth table for 3 arguments:
|
|
10
10
|
*
|
|
@@ -22,7 +22,7 @@ export type XNOR_Binary<T, U> = (T & U) | (Without<T, U> & Without<U, T>);
|
|
|
22
22
|
*/
|
|
23
23
|
export type AND<T extends any[]> = T extends [infer F, ...infer R] ? R extends any[] ? F & AND<R> : F : unknown;
|
|
24
24
|
/**
|
|
25
|
-
* Computes a type-level OR for a tuple of types.
|
|
25
|
+
* Computes a type-level OR (At least one) for a tuple of types.
|
|
26
26
|
*
|
|
27
27
|
* Truth table for 3 arguments:
|
|
28
28
|
*
|
|
@@ -40,7 +40,7 @@ export type AND<T extends any[]> = T extends [infer F, ...infer R] ? R extends a
|
|
|
40
40
|
*/
|
|
41
41
|
export type OR<T extends any[]> = T extends [infer F, ...infer R] ? R extends any[] ? F | OR<R> : F : never;
|
|
42
42
|
/**
|
|
43
|
-
* Computes a type-level XOR for a tuple of types.
|
|
43
|
+
* Computes a type-level XOR (only one/odd) for a tuple of types.
|
|
44
44
|
*
|
|
45
45
|
* Truth table for 3 arguments:
|
|
46
46
|
*
|
|
@@ -58,7 +58,7 @@ export type OR<T extends any[]> = T extends [infer F, ...infer R] ? R extends an
|
|
|
58
58
|
*/
|
|
59
59
|
export type XOR<T extends any[]> = T extends [infer F, ...infer R] ? R extends [infer S, ...infer Rest] ? XOR<[XOR_Binary<F, S>, ...Rest]> : F : never;
|
|
60
60
|
/**
|
|
61
|
-
* Computes a type-level XNOR for a tuple of types.
|
|
61
|
+
* Computes a type-level XNOR (All or None true) for a tuple of types.
|
|
62
62
|
*
|
|
63
63
|
* Truth table for 3 arguments:
|
|
64
64
|
*
|