@reykjavik/webtools 0.2.4 → 0.2.5
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/CHANGELOG.md +8 -1
- package/async.d.ts +6 -2
- package/async.js +21 -2
- package/esm/async.d.ts +6 -2
- package/esm/async.js +21 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
- ... <!-- Add new lines here. -->
|
|
6
6
|
|
|
7
|
+
## 0.2.5
|
|
8
|
+
|
|
9
|
+
_2025-05-21_
|
|
10
|
+
|
|
11
|
+
- `@reykjavik/webtools/async`:
|
|
12
|
+
- feat: Support passing `AbortSignal` to `sleep` and `addLag` helpers
|
|
13
|
+
|
|
7
14
|
## 0.2.4
|
|
8
15
|
|
|
9
16
|
_2025-05-09_
|
|
@@ -39,7 +46,7 @@ _2024-12-17_
|
|
|
39
46
|
_2024-12-12_
|
|
40
47
|
|
|
41
48
|
- feat: Add `@reykjavik/webtools/react-router/*` (previously `/remix/*`)
|
|
42
|
-
- **BREAKING** feat: Remove all `@reykjavik/webtools/
|
|
49
|
+
- **BREAKING** feat: Remove all `@reykjavik/webtools/remix/*` modules
|
|
43
50
|
- **BREAKING** feat: Bump `pkg.engines.node` version to >=20
|
|
44
51
|
- **BREAKING** feat: Remove `@reykjavik/webtools/next/SiteImprove` (deprecated
|
|
45
52
|
module)
|
package/async.d.ts
CHANGED
|
@@ -4,12 +4,16 @@ type PlainObj = Record<string, unknown>;
|
|
|
4
4
|
* Simple sleep function. Returns a promise that resolves after `length`
|
|
5
5
|
* milliseconds.
|
|
6
6
|
*/
|
|
7
|
-
export declare const sleep: (length: number
|
|
7
|
+
export declare const sleep: (length: number, opts?: {
|
|
8
|
+
signal?: AbortSignal;
|
|
9
|
+
}) => Promise<void>;
|
|
8
10
|
/**
|
|
9
11
|
* Returns a function that adds lag/delay to a promise chain,
|
|
10
12
|
* passing the promise payload through.
|
|
11
13
|
*/
|
|
12
|
-
export declare const addLag: (length: number
|
|
14
|
+
export declare const addLag: (length: number, opts?: {
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
}) => <T>(res: T) => Promise<T>;
|
|
13
17
|
/**
|
|
14
18
|
* Resolves as soon as all of the passed `promises` have resolved/settled,
|
|
15
19
|
* or after `timeout` milliseconds — whichever comes first.
|
package/async.js
CHANGED
|
@@ -7,14 +7,33 @@ exports.maxWait = maxWait;
|
|
|
7
7
|
* milliseconds.
|
|
8
8
|
*/
|
|
9
9
|
/*#__NO_SIDE_EFFECTS__*/
|
|
10
|
-
const sleep = (length) => new Promise((resolve) =>
|
|
10
|
+
const sleep = (length, opts) => new Promise((resolve, reject) => {
|
|
11
|
+
const signal = opts && opts.signal;
|
|
12
|
+
if (!signal) {
|
|
13
|
+
return setTimeout(resolve, length);
|
|
14
|
+
}
|
|
15
|
+
if (signal.aborted) {
|
|
16
|
+
return reject(signal.reason);
|
|
17
|
+
}
|
|
18
|
+
const onAbort = () => {
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
20
|
+
clearTimeout(timer);
|
|
21
|
+
signal.removeEventListener('abort', onAbort);
|
|
22
|
+
reject(signal.reason);
|
|
23
|
+
};
|
|
24
|
+
signal.addEventListener('abort', onAbort);
|
|
25
|
+
const timer = setTimeout(() => {
|
|
26
|
+
signal.removeEventListener('abort', onAbort);
|
|
27
|
+
resolve();
|
|
28
|
+
}, length);
|
|
29
|
+
});
|
|
11
30
|
exports.sleep = sleep;
|
|
12
31
|
/**
|
|
13
32
|
* Returns a function that adds lag/delay to a promise chain,
|
|
14
33
|
* passing the promise payload through.
|
|
15
34
|
*/
|
|
16
35
|
/*#__NO_SIDE_EFFECTS__*/
|
|
17
|
-
const addLag = (length) => (res) => (0, exports.sleep)(length).then(() => res);
|
|
36
|
+
const addLag = (length, opts) => (res) => (0, exports.sleep)(length, opts).then(() => res);
|
|
18
37
|
exports.addLag = addLag;
|
|
19
38
|
/*#__NO_SIDE_EFFECTS__*/
|
|
20
39
|
function maxWait(timeout, promises) {
|
package/esm/async.d.ts
CHANGED
|
@@ -4,12 +4,16 @@ type PlainObj = Record<string, unknown>;
|
|
|
4
4
|
* Simple sleep function. Returns a promise that resolves after `length`
|
|
5
5
|
* milliseconds.
|
|
6
6
|
*/
|
|
7
|
-
export declare const sleep: (length: number
|
|
7
|
+
export declare const sleep: (length: number, opts?: {
|
|
8
|
+
signal?: AbortSignal;
|
|
9
|
+
}) => Promise<void>;
|
|
8
10
|
/**
|
|
9
11
|
* Returns a function that adds lag/delay to a promise chain,
|
|
10
12
|
* passing the promise payload through.
|
|
11
13
|
*/
|
|
12
|
-
export declare const addLag: (length: number
|
|
14
|
+
export declare const addLag: (length: number, opts?: {
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
}) => <T>(res: T) => Promise<T>;
|
|
13
17
|
/**
|
|
14
18
|
* Resolves as soon as all of the passed `promises` have resolved/settled,
|
|
15
19
|
* or after `timeout` milliseconds — whichever comes first.
|
package/esm/async.js
CHANGED
|
@@ -3,13 +3,32 @@
|
|
|
3
3
|
* milliseconds.
|
|
4
4
|
*/
|
|
5
5
|
/*#__NO_SIDE_EFFECTS__*/
|
|
6
|
-
export const sleep = (length) => new Promise((resolve) =>
|
|
6
|
+
export const sleep = (length, opts) => new Promise((resolve, reject) => {
|
|
7
|
+
const signal = opts && opts.signal;
|
|
8
|
+
if (!signal) {
|
|
9
|
+
return setTimeout(resolve, length);
|
|
10
|
+
}
|
|
11
|
+
if (signal.aborted) {
|
|
12
|
+
return reject(signal.reason);
|
|
13
|
+
}
|
|
14
|
+
const onAbort = () => {
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
16
|
+
clearTimeout(timer);
|
|
17
|
+
signal.removeEventListener('abort', onAbort);
|
|
18
|
+
reject(signal.reason);
|
|
19
|
+
};
|
|
20
|
+
signal.addEventListener('abort', onAbort);
|
|
21
|
+
const timer = setTimeout(() => {
|
|
22
|
+
signal.removeEventListener('abort', onAbort);
|
|
23
|
+
resolve();
|
|
24
|
+
}, length);
|
|
25
|
+
});
|
|
7
26
|
/**
|
|
8
27
|
* Returns a function that adds lag/delay to a promise chain,
|
|
9
28
|
* passing the promise payload through.
|
|
10
29
|
*/
|
|
11
30
|
/*#__NO_SIDE_EFFECTS__*/
|
|
12
|
-
export const addLag = (length) => (res) => sleep(length).then(() => res);
|
|
31
|
+
export const addLag = (length, opts) => (res) => sleep(length, opts).then(() => res);
|
|
13
32
|
/*#__NO_SIDE_EFFECTS__*/
|
|
14
33
|
export function maxWait(timeout, promises) {
|
|
15
34
|
if (Array.isArray(promises)) {
|
package/package.json
CHANGED