@dxos/async 0.8.4-main.f9ba587 → 0.8.4-main.fcc0d83b33

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.
Files changed (77) hide show
  1. package/dist/lib/browser/index.mjs +306 -269
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +306 -269
  5. package/dist/lib/node-esm/index.mjs.map +4 -4
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/types/src/callback.d.ts +2 -1
  8. package/dist/types/src/callback.d.ts.map +1 -1
  9. package/dist/types/src/chain.d.ts +1 -1
  10. package/dist/types/src/chain.d.ts.map +1 -1
  11. package/dist/types/src/cleanup.d.ts +3 -3
  12. package/dist/types/src/cleanup.d.ts.map +1 -1
  13. package/dist/types/src/debounce.d.ts +37 -3
  14. package/dist/types/src/debounce.d.ts.map +1 -1
  15. package/dist/types/src/errors.d.ts.map +1 -1
  16. package/dist/types/src/event-emitter.d.ts.map +1 -1
  17. package/dist/types/src/events.d.ts.map +1 -1
  18. package/dist/types/src/index.d.ts +0 -5
  19. package/dist/types/src/index.d.ts.map +1 -1
  20. package/dist/types/src/mutex.d.ts.map +1 -1
  21. package/dist/types/src/observable-value.d.ts.map +1 -1
  22. package/dist/types/src/observable.d.ts.map +1 -1
  23. package/dist/types/src/persistent-lifecycle.d.ts +2 -2
  24. package/dist/types/src/persistent-lifecycle.d.ts.map +1 -1
  25. package/dist/types/src/stream-to-array.d.ts.map +1 -1
  26. package/dist/types/src/task-scheduling.d.ts +29 -1
  27. package/dist/types/src/task-scheduling.d.ts.map +1 -1
  28. package/dist/types/src/test-stream.d.ts.map +1 -1
  29. package/dist/types/src/testing.d.ts +13 -0
  30. package/dist/types/src/testing.d.ts.map +1 -1
  31. package/dist/types/src/timeout.d.ts +2 -2
  32. package/dist/types/src/timeout.d.ts.map +1 -1
  33. package/dist/types/src/timer.d.ts.map +1 -1
  34. package/dist/types/src/track-leaks.d.ts.map +1 -1
  35. package/dist/types/src/trigger.d.ts +11 -0
  36. package/dist/types/src/trigger.d.ts.map +1 -1
  37. package/dist/types/src/update-scheduler.d.ts.map +1 -1
  38. package/dist/types/tsconfig.tsbuildinfo +1 -1
  39. package/package.json +13 -12
  40. package/src/callback.ts +3 -3
  41. package/src/chain.ts +1 -1
  42. package/src/cleanup.ts +10 -7
  43. package/src/debounce.test.ts +69 -12
  44. package/src/debounce.ts +88 -14
  45. package/src/event-emitter.test.ts +1 -1
  46. package/src/index.ts +0 -5
  47. package/src/observable-value.test.ts +1 -1
  48. package/src/observable-value.ts +4 -2
  49. package/src/persistent-lifecycle.test.ts +1 -1
  50. package/src/persistent-lifecycle.ts +2 -2
  51. package/src/task-scheduling.ts +95 -1
  52. package/src/testing.test.ts +41 -1
  53. package/src/testing.ts +53 -0
  54. package/src/timeout.ts +27 -29
  55. package/src/trigger.ts +58 -1
  56. package/src/update-scheduler.ts +1 -1
  57. package/dist/types/src/latch.d.ts +0 -11
  58. package/dist/types/src/latch.d.ts.map +0 -1
  59. package/dist/types/src/sink.d.ts +0 -6
  60. package/dist/types/src/sink.d.ts.map +0 -1
  61. package/dist/types/src/throttle.d.ts +0 -2
  62. package/dist/types/src/throttle.d.ts.map +0 -1
  63. package/dist/types/src/throttle.test.d.ts +0 -2
  64. package/dist/types/src/throttle.test.d.ts.map +0 -1
  65. package/dist/types/src/types.d.ts +0 -2
  66. package/dist/types/src/types.d.ts.map +0 -1
  67. package/dist/types/src/until.d.ts +0 -14
  68. package/dist/types/src/until.d.ts.map +0 -1
  69. package/dist/types/src/until.test.d.ts +0 -2
  70. package/dist/types/src/until.test.d.ts.map +0 -1
  71. package/src/latch.ts +0 -60
  72. package/src/sink.ts +0 -26
  73. package/src/throttle.test.ts +0 -65
  74. package/src/throttle.ts +0 -14
  75. package/src/types.ts +0 -5
  76. package/src/until.test.ts +0 -47
  77. package/src/until.ts +0 -58
package/src/timeout.ts CHANGED
@@ -4,7 +4,6 @@
4
4
 
5
5
  import { type Context, ContextDisposedError } from '@dxos/context';
6
6
 
7
- import { createPromiseFromCallback } from './callback';
8
7
  import { TimeoutError } from './errors';
9
8
 
10
9
  /**
@@ -28,6 +27,27 @@ export const sleep = (ms: number) => {
28
27
  });
29
28
  };
30
29
 
30
+ // TODO(burdon): Reconcile with sleep.
31
+ export const sleepWithContext = (ctx: Context, ms: number) => {
32
+ const error = new ContextDisposedError();
33
+ return new Promise<void>((resolve, reject) => {
34
+ if (ctx.disposed) {
35
+ reject(error);
36
+ return;
37
+ }
38
+
39
+ const timeout = setTimeout(() => {
40
+ clearDispose();
41
+ resolve();
42
+ }, ms);
43
+
44
+ const clearDispose = ctx.onDispose(() => {
45
+ clearTimeout(timeout);
46
+ reject(error);
47
+ });
48
+ });
49
+ };
50
+
31
51
  /**
32
52
  * Can be used in long-running tasks to let other callbacks be invoked.
33
53
  */
@@ -36,12 +56,11 @@ export const asyncReturn = () => sleep(0);
36
56
  /**
37
57
  * Wait for promise or throw error.
38
58
  */
39
- export const asyncTimeout = async <T>(
40
- // TODO(dmaretskyi): This callback API is unintuitive and leads to bugs.
41
- promise: Promise<T> | (() => Promise<T>),
42
- timeout: number,
43
- err?: Error | string,
44
- ): Promise<T> => {
59
+ export const asyncTimeout = async <T>(promise: Promise<T>, timeout: number, err?: Error | string): Promise<T> => {
60
+ if (typeof promise === 'function') {
61
+ throw new Error('First argument must be a promise.');
62
+ }
63
+
45
64
  let timeoutId: NodeJS.Timeout;
46
65
  const throwable = err === undefined || typeof err === 'string' ? new TimeoutError(timeout, err) : err;
47
66
  const timeoutPromise = new Promise<T>((resolve, reject) => {
@@ -52,8 +71,7 @@ export const asyncTimeout = async <T>(
52
71
  unrefTimeout(timeoutId);
53
72
  });
54
73
 
55
- const conditionTimeout = typeof promise === 'function' ? createPromiseFromCallback<T>(promise) : promise;
56
- return await Promise.race([conditionTimeout, timeoutPromise]).finally(() => {
74
+ return await Promise.race([promise, timeoutPromise]).finally(() => {
57
75
  clearTimeout(timeoutId);
58
76
  });
59
77
  };
@@ -67,23 +85,3 @@ export const unrefTimeout = (timeoutId: NodeJS.Timeout) => {
67
85
  timeoutId.unref();
68
86
  }
69
87
  };
70
-
71
- export const sleepWithContext = (ctx: Context, ms: number) => {
72
- const error = new ContextDisposedError();
73
- return new Promise<void>((resolve, reject) => {
74
- if (ctx.disposed) {
75
- reject(error);
76
- return;
77
- }
78
-
79
- const timeout = setTimeout(() => {
80
- clearDispose();
81
- resolve();
82
- }, ms);
83
-
84
- const clearDispose = ctx.onDispose(() => {
85
- clearTimeout(timeout);
86
- reject(error);
87
- });
88
- });
89
- };
package/src/trigger.ts CHANGED
@@ -2,6 +2,8 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
+ import { invariant } from '@dxos/invariant';
6
+
5
7
  import { TimeoutError } from './errors';
6
8
  import { asyncTimeout } from './timeout';
7
9
 
@@ -10,7 +12,7 @@ import { asyncTimeout } from './timeout';
10
12
  * @deprecated Use `Trigger` instead.
11
13
  */
12
14
  export const trigger = <T = void>(timeout?: number): [() => Promise<T>, (arg: T) => void] => {
13
- // eslint-disable-line @stayradiated/prefer-arrow-functions/prefer-arrow-functions
15
+ // eslint-disable-line prefer-arrow-functions/prefer-arrow-functions
14
16
  let callback: (arg: T) => void;
15
17
 
16
18
  const promise = new Promise<T>((resolve, reject) => {
@@ -121,3 +123,58 @@ export class Trigger<T = void> {
121
123
  return this;
122
124
  }
123
125
  }
126
+
127
+ type LatchProps = {
128
+ count?: number;
129
+ timeout?: number;
130
+ };
131
+
132
+ type LatchResult = [() => Promise<number>, () => number, (err: Error) => void];
133
+
134
+ /**
135
+ * Returns a callback and a promise that's resolved when the callback is called n times.
136
+ * @deprecated Use `Trigger` instead.
137
+ */
138
+ export const latch = ({ count = 1, timeout }: LatchProps = {}): LatchResult => {
139
+ invariant(count >= 0);
140
+
141
+ let t: ReturnType<typeof setTimeout>;
142
+ let doResolve: (value: number) => void;
143
+ let doReject: (err: Error) => void;
144
+ const promise = new Promise<number>((resolve, reject) => {
145
+ doResolve = (value) => {
146
+ clearTimeout(t);
147
+ resolve(value);
148
+ };
149
+
150
+ doReject = (err) => {
151
+ clearTimeout(t);
152
+ reject(err);
153
+ };
154
+ });
155
+
156
+ if (count === 0) {
157
+ setTimeout(() => {
158
+ doResolve(0);
159
+ });
160
+ } else {
161
+ if (timeout) {
162
+ t = setTimeout(() => {
163
+ doReject(new Error(`Timed out after ${timeout.toLocaleString()}ms`));
164
+ }, timeout);
165
+ }
166
+ }
167
+
168
+ let i = 0;
169
+ return [
170
+ async () => await promise,
171
+ () => {
172
+ if (++i === count) {
173
+ doResolve(i);
174
+ }
175
+
176
+ return i;
177
+ },
178
+ (err: Error) => doReject(err),
179
+ ];
180
+ };
@@ -16,7 +16,7 @@ export type UpdateSchedulerOptions = {
16
16
  /**
17
17
  * Time period for update counting.
18
18
  */
19
- const TIME_PERIOD = 1000;
19
+ const TIME_PERIOD = 1_000;
20
20
 
21
21
  export class UpdateScheduler {
22
22
  /**
@@ -1,11 +0,0 @@
1
- type LatchProps = {
2
- count?: number;
3
- timeout?: number;
4
- };
5
- type LatchResult = [() => Promise<number>, () => number, (err: Error) => void];
6
- /**
7
- * Returns a callback and a promise that's resolved when the callback is called n times.
8
- */
9
- export declare const latch: ({ count, timeout }?: LatchProps) => LatchResult;
10
- export {};
11
- //# sourceMappingURL=latch.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"latch.d.ts","sourceRoot":"","sources":["../../../src/latch.ts"],"names":[],"mappings":"AAMA,KAAK,UAAU,GAAG;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,KAAK,WAAW,GAAG,CAAC,MAAM,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,MAAM,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAAC,CAAC;AAE/E;;GAEG;AAEH,eAAO,MAAM,KAAK,GAAI,qBAAwB,UAAe,KAAG,WA0C/D,CAAC"}
@@ -1,6 +0,0 @@
1
- import { type EventEmitter } from 'node:events';
2
- /**
3
- * Waits for the specified number of events from the given emitter.
4
- */
5
- export declare const sink: (emitter: EventEmitter, event: string, count?: number) => Promise<void>;
6
- //# sourceMappingURL=sink.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sink.d.ts","sourceRoot":"","sources":["../../../src/sink.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAIhD;;GAEG;AACH,eAAO,MAAM,IAAI,GAAI,SAAS,YAAY,EAAE,OAAO,MAAM,EAAE,cAAS,KAAG,OAAO,CAAC,IAAI,CAclF,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare const throttle: (cb: (...args: any[]) => void, wait?: number) => ((...args: any[]) => void);
2
- //# sourceMappingURL=throttle.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"throttle.d.ts","sourceRoot":"","sources":["../../../src/throttle.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,QAAQ,GAAI,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,EAAE,aAAU,KAAG,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAS5F,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=throttle.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"throttle.test.d.ts","sourceRoot":"","sources":["../../../src/throttle.test.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export type Awaited<T> = T extends Promise<infer U> ? U : T;
2
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC"}
@@ -1,14 +0,0 @@
1
- export type UntilCallback<T> = (resolve: (value: T) => void, reject: (error: Error) => void) => Promise<T> | void;
2
- /**
3
- * Awaits promise.
4
- */
5
- export declare const until: <T = void>(cb: UntilCallback<T>, timeout?: number) => Promise<T>;
6
- /**
7
- * Wait until promise resolves.
8
- */
9
- export declare const untilPromise: <T = void>(cb: () => Promise<T>) => Promise<T>;
10
- /**
11
- * Wait until error is thrown.
12
- */
13
- export declare const untilError: (cb: () => Promise<any>) => Promise<unknown>;
14
- //# sourceMappingURL=until.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"until.d.ts","sourceRoot":"","sources":["../../../src/until.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;AAElH;;GAEG;AAEH,eAAO,MAAM,KAAK,GAAI,CAAC,GAAG,IAAI,EAAE,IAAI,aAAa,CAAC,CAAC,CAAC,EAAE,UAAU,MAAM,KAAG,OAAO,CAAC,CAAC,CAyBjF,CAAC;AAEF;;GAEG;AAEH,eAAO,MAAM,YAAY,GAAI,CAAC,GAAG,IAAI,EAAE,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC,eAAS,CAAC;AAErE;;GAEG;AACH,eAAO,MAAM,UAAU,GAAI,IAAI,MAAM,OAAO,CAAC,GAAG,CAAC,qBAWhD,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=until.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"until.test.d.ts","sourceRoot":"","sources":["../../../src/until.test.ts"],"names":[],"mappings":""}
package/src/latch.ts DELETED
@@ -1,60 +0,0 @@
1
- //
2
- // Copyright 2020 DXOS.org
3
- //
4
-
5
- import { invariant } from '@dxos/invariant';
6
-
7
- type LatchProps = {
8
- count?: number;
9
- timeout?: number;
10
- };
11
-
12
- type LatchResult = [() => Promise<number>, () => number, (err: Error) => void];
13
-
14
- /**
15
- * Returns a callback and a promise that's resolved when the callback is called n times.
16
- */
17
- // TODO(burdon): Reconcile with until/trigger.
18
- export const latch = ({ count = 1, timeout }: LatchProps = {}): LatchResult => {
19
- invariant(count >= 0);
20
-
21
- let t: ReturnType<typeof setTimeout>;
22
- let doResolve: (value: number) => void;
23
- let doReject: (err: Error) => void;
24
- const promise = new Promise<number>((resolve, reject) => {
25
- doResolve = (value) => {
26
- clearTimeout(t);
27
- resolve(value);
28
- };
29
-
30
- doReject = (err) => {
31
- clearTimeout(t);
32
- reject(err);
33
- };
34
- });
35
-
36
- if (count === 0) {
37
- setTimeout(() => {
38
- doResolve(0);
39
- });
40
- } else {
41
- if (timeout) {
42
- t = setTimeout(() => {
43
- doReject(new Error(`Timed out after ${timeout.toLocaleString()}ms`));
44
- }, timeout);
45
- }
46
- }
47
-
48
- let i = 0;
49
- return [
50
- async () => await promise,
51
- () => {
52
- if (++i === count) {
53
- doResolve(i);
54
- }
55
-
56
- return i;
57
- },
58
- (err: Error) => doReject(err),
59
- ];
60
- };
package/src/sink.ts DELETED
@@ -1,26 +0,0 @@
1
- //
2
- // Copyright 2020 DXOS.org
3
- //
4
-
5
- import { type EventEmitter } from 'node:events';
6
-
7
- import { trigger } from './trigger';
8
-
9
- /**
10
- * Waits for the specified number of events from the given emitter.
11
- */
12
- export const sink = (emitter: EventEmitter, event: string, count = 1): Promise<void> => {
13
- const [getPromise, resolve] = trigger();
14
-
15
- let counter = 0;
16
- const listener = () => {
17
- if (++counter === count) {
18
- emitter.off(event, listener);
19
- resolve();
20
- }
21
- };
22
-
23
- emitter.on(event, listener);
24
-
25
- return getPromise();
26
- };
@@ -1,65 +0,0 @@
1
- //
2
- // Copyright 2020 DXOS.org
3
- //
4
-
5
- import { describe, expect, test } from 'vitest';
6
-
7
- import { throttle } from './throttle';
8
- import { sleep } from './timeout';
9
-
10
- describe('throttle', () => {
11
- test('throttles function calls', async () => {
12
- let count = 0;
13
- const fn = throttle(() => count++, 100);
14
-
15
- // First call should execute immediately
16
- fn();
17
- expect(count).toBe(1);
18
-
19
- // Second call within throttle window should not execute
20
- fn();
21
- expect(count).toBe(1);
22
-
23
- // Wait for throttle window to pass
24
- await sleep(150);
25
-
26
- // Next call should execute
27
- fn();
28
- expect(count).toBe(2);
29
- });
30
-
31
- test('passes arguments to throttled function', async () => {
32
- let lastArgs: any[] = [];
33
- const fn = throttle((...args: any[]) => {
34
- lastArgs = args;
35
- }, 100);
36
-
37
- fn('test', 123);
38
- expect(lastArgs).toEqual(['test', 123]);
39
-
40
- // Call with different args within throttle window
41
- fn('different', 456);
42
- expect(lastArgs).toEqual(['test', 123]); // Should not update
43
-
44
- await sleep(150);
45
- fn('new', 789);
46
- expect(lastArgs).toEqual(['new', 789]);
47
- });
48
-
49
- test('handles multiple rapid calls', async () => {
50
- let count = 0;
51
- const fn = throttle(() => count++, 100);
52
-
53
- // Make multiple rapid calls
54
- for (let i = 0; i < 5; i++) {
55
- fn();
56
- }
57
- expect(count).toBe(1); // Only first call should execute
58
-
59
- await sleep(150);
60
- expect(count).toBe(1); // Still only one execution
61
-
62
- fn();
63
- expect(count).toBe(2); // Next call after wait should execute
64
- });
65
- });
package/src/throttle.ts DELETED
@@ -1,14 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- export const throttle = (cb: (...args: any[]) => void, wait = 100): ((...args: any[]) => void) => {
6
- let lastCall = 0;
7
- return (...args: any[]) => {
8
- const now = Date.now();
9
- if (now - lastCall >= wait) {
10
- cb(...args);
11
- lastCall = now;
12
- }
13
- };
14
- };
package/src/types.ts DELETED
@@ -1,5 +0,0 @@
1
- //
2
- // Copyright 2021 DXOS.org
3
- //
4
-
5
- export type Awaited<T> = T extends Promise<infer U> ? U : T;
package/src/until.test.ts DELETED
@@ -1,47 +0,0 @@
1
- //
2
- // Copyright 2020 DXOS.org
3
- //
4
-
5
- import { describe, expect, test } from 'vitest';
6
-
7
- import { sleep } from './timeout';
8
- import { until } from './until';
9
-
10
- describe('until', () => {
11
- test('success', async () => {
12
- const value = await until<number>(async (resolve) => {
13
- await sleep(100);
14
- resolve(100);
15
- return 1;
16
- });
17
-
18
- expect(value).to.equal(100);
19
- });
20
-
21
- test('error', async () => {
22
- await expect(async () => {
23
- await until(async (resolve, reject) => {
24
- await sleep(100);
25
- reject(new Error());
26
- });
27
- }).rejects.toThrowError();
28
- });
29
-
30
- test('catch', async () => {
31
- await expect(async () => {
32
- await until(async () => {
33
- await sleep(100);
34
- throw new Error();
35
- });
36
- }).rejects.toThrowError();
37
- });
38
-
39
- test('timeout', async () => {
40
- await expect(async () => {
41
- await until(async (resolve) => {
42
- await sleep(500);
43
- resolve();
44
- }, 100); // Timeout before complete.
45
- }).rejects.toThrowError();
46
- });
47
- });
package/src/until.ts DELETED
@@ -1,58 +0,0 @@
1
- //
2
- // Copyright 2022 DXOS.org
3
- //
4
-
5
- export type UntilCallback<T> = (resolve: (value: T) => void, reject: (error: Error) => void) => Promise<T> | void;
6
-
7
- /**
8
- * Awaits promise.
9
- */
10
- // TODO(burdon): Reconcile with latch/trigger.
11
- export const until = <T = void>(cb: UntilCallback<T>, timeout?: number): Promise<T> => {
12
- return new Promise((resolve, reject) => {
13
- const t =
14
- timeout &&
15
- setTimeout(() => {
16
- reject(new Error(`Timeout after ${t}ms`));
17
- }, timeout);
18
-
19
- setTimeout(async () => {
20
- try {
21
- await cb(
22
- (value: T) => {
23
- t && clearTimeout(t);
24
- resolve(value);
25
- },
26
- (error: Error) => {
27
- t && clearTimeout(t);
28
- reject(error);
29
- },
30
- );
31
- } catch (err) {
32
- reject(err);
33
- }
34
- });
35
- });
36
- };
37
-
38
- /**
39
- * Wait until promise resolves.
40
- */
41
- // TODO(burdon): Reconcile promises (with timeouts).
42
- export const untilPromise = <T = void>(cb: () => Promise<T>) => cb();
43
-
44
- /**
45
- * Wait until error is thrown.
46
- */
47
- export const untilError = (cb: () => Promise<any>) => {
48
- return new Promise((resolve, reject) => {
49
- setTimeout(async () => {
50
- try {
51
- await cb();
52
- reject(new Error('No error was thrown.'));
53
- } catch (err) {
54
- resolve(err);
55
- }
56
- });
57
- });
58
- };