@peerbit/time 2.0.0 → 2.0.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/lib/esm/index.d.ts +3 -3
- package/lib/esm/index.js +7 -6
- package/lib/esm/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +13 -10
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare class TimeoutError extends Error {
|
|
2
|
-
constructor(message
|
|
2
|
+
constructor(message?: string);
|
|
3
3
|
}
|
|
4
4
|
export declare class AbortError extends Error {
|
|
5
|
-
constructor();
|
|
5
|
+
constructor(message?: string);
|
|
6
6
|
}
|
|
7
7
|
export declare const delay: (ms: number, options?: {
|
|
8
8
|
signal?: AbortSignal;
|
|
@@ -18,4 +18,4 @@ export declare const waitForResolved: <T>(fn: () => T | Promise<T>, options?: {
|
|
|
18
18
|
signal?: AbortSignal;
|
|
19
19
|
delayInterval?: number;
|
|
20
20
|
timeoutMessage?: string;
|
|
21
|
-
}) => Promise<T
|
|
21
|
+
}) => Promise<T>;
|
package/lib/esm/index.js
CHANGED
|
@@ -4,8 +4,8 @@ export class TimeoutError extends Error {
|
|
|
4
4
|
}
|
|
5
5
|
}
|
|
6
6
|
export class AbortError extends Error {
|
|
7
|
-
constructor() {
|
|
8
|
-
super();
|
|
7
|
+
constructor(message) {
|
|
8
|
+
super(message);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
export const delay = (ms, options) => {
|
|
@@ -21,6 +21,9 @@ export const delay = (ms, options) => {
|
|
|
21
21
|
}, ms);
|
|
22
22
|
});
|
|
23
23
|
};
|
|
24
|
+
const createTimeoutError = (options) => new TimeoutError(options?.timeoutMessage
|
|
25
|
+
? "Timed out: " + options?.timeoutMessage
|
|
26
|
+
: "Timed out");
|
|
24
27
|
export const waitFor = async (fn, options = { timeout: 10 * 1000, delayInterval: 100 }) => {
|
|
25
28
|
const delayInterval = options.delayInterval || 100;
|
|
26
29
|
const timeout = options.timeout || 10 * 1000;
|
|
@@ -39,9 +42,7 @@ export const waitFor = async (fn, options = { timeout: 10 * 1000, delayInterval:
|
|
|
39
42
|
}
|
|
40
43
|
await delay(delayInterval, options);
|
|
41
44
|
}
|
|
42
|
-
throw
|
|
43
|
-
? "Timed out: " + options.timeoutMessage
|
|
44
|
-
: "Timed out");
|
|
45
|
+
throw createTimeoutError(options);
|
|
45
46
|
};
|
|
46
47
|
export const waitForResolved = async (fn, options = { timeout: 10 * 1000, delayInterval: 50 }) => {
|
|
47
48
|
const delayInterval = options.delayInterval || 50;
|
|
@@ -70,6 +71,6 @@ export const waitForResolved = async (fn, options = { timeout: 10 * 1000, delayI
|
|
|
70
71
|
}
|
|
71
72
|
await delay(delayInterval, options);
|
|
72
73
|
}
|
|
73
|
-
throw lastError;
|
|
74
|
+
throw lastError || createTimeoutError(options);
|
|
74
75
|
};
|
|
75
76
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,YAAa,SAAQ,KAAK;IACtC,YAAY,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,YAAa,SAAQ,KAAK;IACtC,YAAY,OAAgB;QAC3B,KAAK,CAAC,OAAO,CAAC,CAAC;IAChB,CAAC;CACD;AAED,MAAM,OAAO,UAAW,SAAQ,KAAK;IACpC,YAAY,OAAgB;QAC3B,KAAK,CAAC,OAAO,CAAC,CAAC;IAChB,CAAC;CACD;AACD,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,OAAkC,EAAE,EAAE;IACvE,OAAO,IAAI,OAAO,CAAO,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QACrC,SAAS,WAAW;YACnB,YAAY,CAAC,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C;QAAC,OAAO,KAAU,EAAE,CAAC;YACrB,IAAI,KAAK,YAAY,UAAU,KAAK,KAAK,EAAE,CAAC;gBAC3C,SAAS,GAAG,KAAK,CAAC;YACnB,CAAC;iBAAM,CAAC;gBACP,MAAM,KAAK,CAAC;YACb,CAAC;QACF,CAAC;QACD,MAAM,KAAK,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IACrC,CAAC;IAED,MAAM,SAAS,IAAI,kBAAkB,CAAC,OAAO,CAAC,CAAC;AAChD,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peerbit/time",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Utility functions for time",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
},
|
|
30
30
|
"author": "dao.xyz",
|
|
31
31
|
"license": "MIT",
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "a9a953326be9f26ded767042964c1a42451107a4"
|
|
33
33
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export class TimeoutError extends Error {
|
|
2
|
-
constructor(message
|
|
2
|
+
constructor(message?: string) {
|
|
3
3
|
super(message);
|
|
4
4
|
}
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
export class AbortError extends Error {
|
|
8
|
-
constructor() {
|
|
9
|
-
super();
|
|
8
|
+
constructor(message?: string) {
|
|
9
|
+
super(message);
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
export const delay = (ms: number, options?: { signal?: AbortSignal }) => {
|
|
@@ -23,6 +23,13 @@ export const delay = (ms: number, options?: { signal?: AbortSignal }) => {
|
|
|
23
23
|
});
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
+
const createTimeoutError = (options: { timeoutMessage?: string }) =>
|
|
27
|
+
new TimeoutError(
|
|
28
|
+
options?.timeoutMessage
|
|
29
|
+
? "Timed out: " + options?.timeoutMessage
|
|
30
|
+
: "Timed out"
|
|
31
|
+
);
|
|
32
|
+
|
|
26
33
|
export const waitFor = async <T>(
|
|
27
34
|
fn: () => T | Promise<T>,
|
|
28
35
|
options: {
|
|
@@ -52,11 +59,7 @@ export const waitFor = async <T>(
|
|
|
52
59
|
|
|
53
60
|
await delay(delayInterval, options);
|
|
54
61
|
}
|
|
55
|
-
throw
|
|
56
|
-
options.timeoutMessage
|
|
57
|
-
? "Timed out: " + options.timeoutMessage
|
|
58
|
-
: "Timed out"
|
|
59
|
-
);
|
|
62
|
+
throw createTimeoutError(options);
|
|
60
63
|
};
|
|
61
64
|
|
|
62
65
|
export const waitForResolved = async <T>(
|
|
@@ -67,7 +70,7 @@ export const waitForResolved = async <T>(
|
|
|
67
70
|
delayInterval?: number;
|
|
68
71
|
timeoutMessage?: string;
|
|
69
72
|
} = { timeout: 10 * 1000, delayInterval: 50 }
|
|
70
|
-
): Promise<T
|
|
73
|
+
): Promise<T> => {
|
|
71
74
|
const delayInterval = options.delayInterval || 50;
|
|
72
75
|
const timeout = options.timeout || 10 * 1000;
|
|
73
76
|
|
|
@@ -96,5 +99,5 @@ export const waitForResolved = async <T>(
|
|
|
96
99
|
await delay(delayInterval, options);
|
|
97
100
|
}
|
|
98
101
|
|
|
99
|
-
throw lastError;
|
|
102
|
+
throw lastError || createTimeoutError(options);
|
|
100
103
|
};
|