@byloth/core 1.5.3 → 2.0.0-rc.10

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 (45) hide show
  1. package/dist/core.js +1468 -826
  2. package/dist/core.js.map +1 -1
  3. package/dist/core.umd.cjs +3 -3
  4. package/dist/core.umd.cjs.map +1 -1
  5. package/package.json +8 -10
  6. package/src/helpers.ts +10 -0
  7. package/src/index.ts +33 -16
  8. package/src/models/aggregators/aggregated-async-iterator.ts +129 -81
  9. package/src/models/aggregators/aggregated-iterator.ts +128 -82
  10. package/src/models/aggregators/index.ts +1 -3
  11. package/src/models/aggregators/reduced-iterator.ts +119 -31
  12. package/src/models/aggregators/types.ts +15 -10
  13. package/src/models/callbacks/callable-object.ts +23 -0
  14. package/src/models/callbacks/index.ts +5 -0
  15. package/src/models/callbacks/publisher.ts +45 -0
  16. package/src/models/callbacks/switchable-callback.ts +108 -0
  17. package/src/models/callbacks/types.ts +1 -0
  18. package/src/models/exceptions/core.ts +6 -7
  19. package/src/models/exceptions/index.ts +50 -10
  20. package/src/models/game-loop.ts +83 -0
  21. package/src/models/index.ts +10 -7
  22. package/src/models/iterators/smart-async-iterator.ts +112 -24
  23. package/src/models/iterators/smart-iterator.ts +108 -13
  24. package/src/models/iterators/types.ts +17 -7
  25. package/src/models/json/index.ts +3 -0
  26. package/src/models/{json-storage.ts → json/json-storage.ts} +40 -28
  27. package/src/models/json/types.ts +5 -0
  28. package/src/models/promises/deferred-promise.ts +1 -1
  29. package/src/models/promises/index.ts +3 -1
  30. package/src/models/promises/long-running-task.ts +294 -0
  31. package/src/models/promises/smart-promise.ts +6 -1
  32. package/src/models/promises/thenable.ts +97 -0
  33. package/src/models/promises/timed-promise.ts +1 -1
  34. package/src/models/promises/types.ts +2 -0
  35. package/src/models/timers/clock.ts +69 -0
  36. package/src/models/timers/countdown.ts +117 -0
  37. package/src/models/timers/index.ts +4 -0
  38. package/src/models/types.ts +20 -9
  39. package/src/utils/async.ts +9 -4
  40. package/src/utils/date.ts +7 -4
  41. package/src/utils/index.ts +2 -2
  42. package/src/utils/random.ts +4 -3
  43. package/src/models/aggregators/aggregator.ts +0 -46
  44. package/src/models/aggregators/async-aggregator.ts +0 -56
  45. package/src/models/subscribers.ts +0 -35
@@ -0,0 +1,294 @@
1
+ import { yieldToEventLoop } from "../../utils/async.js";
2
+
3
+ import Publisher from "../callbacks/publisher.js";
4
+ import { RuntimeException } from "../exceptions/index.js";
5
+
6
+ import type { MaybeAsyncGeneratorFunction } from "../iterators/types.js";
7
+ import type { FulfilledHandler, PromiseExecutor, RejectedHandler } from "./types.js";
8
+
9
+ export interface LongRunningTaskOptions
10
+ {
11
+ ignoreErrors?: boolean;
12
+ stepIncrement?: number;
13
+ totalSteps?: number | null;
14
+ trackProgress?: boolean;
15
+ }
16
+
17
+ export default class LongRunningTask<T = void> implements Promise<T>
18
+ {
19
+ private static get _DefaultOptions(): Required<LongRunningTaskOptions>
20
+ {
21
+ return {
22
+ ignoreErrors: false,
23
+ stepIncrement: 1,
24
+ totalSteps: null,
25
+ trackProgress: false
26
+ };
27
+ }
28
+
29
+ protected _startTime: number;
30
+ protected _estimatedTime: number;
31
+ protected _endTime?: number;
32
+
33
+ protected _currentStep: number;
34
+ protected _percentage: number;
35
+
36
+ protected _isRunning: boolean;
37
+ protected _hasCompleted: boolean;
38
+ protected _hasFailed: boolean;
39
+
40
+ protected _promise: Promise<T>;
41
+ protected _publisher?: Publisher;
42
+
43
+ public constructor(executor: MaybeAsyncGeneratorFunction<undefined, T>, options?: LongRunningTaskOptions);
44
+ public constructor(executor: MaybeAsyncGeneratorFunction<number, T>, options?: LongRunningTaskOptions);
45
+ public constructor(executor: MaybeAsyncGeneratorFunction<number | undefined, T>, options?: LongRunningTaskOptions)
46
+ {
47
+ this._startTime = 0;
48
+ this._estimatedTime = 0;
49
+
50
+ this._currentStep = 0;
51
+ this._percentage = 0;
52
+
53
+ this._isRunning = true;
54
+ this._hasCompleted = false;
55
+ this._hasFailed = false;
56
+
57
+ const _onFulfilled = (result: T): T =>
58
+ {
59
+ this._estimatedTime = 0;
60
+ this._endTime = Date.now();
61
+
62
+ this._percentage = 100;
63
+
64
+ this._isRunning = false;
65
+ this._hasCompleted = true;
66
+
67
+ return result;
68
+ };
69
+ const _onRejected = (reason: unknown): never =>
70
+ {
71
+ this._endTime = Date.now();
72
+
73
+ this._isRunning = false;
74
+ this._hasFailed = true;
75
+
76
+ throw reason;
77
+ };
78
+
79
+ let _executor: PromiseExecutor<T>;
80
+
81
+ options = { ...LongRunningTask._DefaultOptions, ...options };
82
+ if ((options.trackProgress))
83
+ {
84
+ let _trackProgress: (steps: number | undefined) => void;
85
+
86
+ this._publisher = new Publisher();
87
+
88
+ if (options.totalSteps)
89
+ {
90
+ if (options.stepIncrement)
91
+ {
92
+ _trackProgress = (steps: number | undefined) =>
93
+ {
94
+ if (steps) { this._currentStep += steps; }
95
+ else { this._currentStep += options.stepIncrement!; }
96
+
97
+ this._percentage = (this._currentStep / options.totalSteps!) * 100;
98
+
99
+ const elapsedTime = Date.now() - this._startTime;
100
+ const remainingSteps = options.totalSteps! - this._currentStep;
101
+ this._estimatedTime = (elapsedTime / this._currentStep) * remainingSteps;
102
+ };
103
+ }
104
+ else
105
+ {
106
+ _trackProgress = (steps: number | undefined) =>
107
+ {
108
+ if (steps)
109
+ {
110
+ this._currentStep += steps;
111
+ this._percentage = (this._currentStep / options.totalSteps!) * 100;
112
+
113
+ const elapsedTime = Date.now() - this._startTime;
114
+ const remainingSteps = options.totalSteps! - this._currentStep;
115
+ this._estimatedTime = (elapsedTime / this._currentStep) * remainingSteps;
116
+ }
117
+ };
118
+ }
119
+ }
120
+ else if (options.stepIncrement)
121
+ {
122
+ _trackProgress = (steps: number | undefined) =>
123
+ {
124
+ if (steps) { this._currentStep += steps; }
125
+ else { this._currentStep += options.stepIncrement!; }
126
+ };
127
+ }
128
+ else
129
+ {
130
+ _trackProgress = (steps: number | undefined) =>
131
+ {
132
+ if (steps) { this._currentStep += steps; }
133
+ };
134
+ }
135
+
136
+ if (options.ignoreErrors)
137
+ {
138
+ _executor = async (resolve) =>
139
+ {
140
+ const generator = executor();
141
+ this._startTime = Date.now();
142
+
143
+ while (true)
144
+ {
145
+ try
146
+ {
147
+ const { done, value } = await generator.next();
148
+
149
+ if (done) { return resolve(value); }
150
+ else { _trackProgress(value); }
151
+ }
152
+
153
+ // eslint-disable-next-line no-console
154
+ catch (error) { console.error(error); }
155
+
156
+ this._publisher!.publish("progress");
157
+
158
+ await yieldToEventLoop();
159
+ }
160
+ };
161
+ }
162
+ else
163
+ {
164
+ _executor = async (resolve, reject) =>
165
+ {
166
+ try
167
+ {
168
+ const generator = executor();
169
+ this._startTime = Date.now();
170
+
171
+ while (true)
172
+ {
173
+ const { done, value } = await generator.next();
174
+ if (done) { return resolve(value); }
175
+ else { _trackProgress(value); }
176
+
177
+ this._publisher!.publish("progress");
178
+
179
+ await yieldToEventLoop();
180
+ }
181
+ }
182
+ catch (error) { reject(error); }
183
+ };
184
+ }
185
+ }
186
+ else if (options.ignoreErrors)
187
+ {
188
+ _executor = async (resolve) =>
189
+ {
190
+ const generator = executor();
191
+ this._startTime = Date.now();
192
+
193
+ while (true)
194
+ {
195
+ try
196
+ {
197
+ const { done, value } = await generator.next();
198
+ if (done) { return resolve(value); }
199
+ }
200
+
201
+ // eslint-disable-next-line no-console
202
+ catch (error) { console.error(error); }
203
+
204
+ await yieldToEventLoop();
205
+ }
206
+ };
207
+ }
208
+ else
209
+ {
210
+ _executor = async (resolve, reject) =>
211
+ {
212
+ try
213
+ {
214
+ const generator = executor();
215
+ this._startTime = Date.now();
216
+
217
+ while (true)
218
+ {
219
+ const { done, value } = await generator.next();
220
+ if (done) { return resolve(value); }
221
+
222
+ await yieldToEventLoop();
223
+ }
224
+ }
225
+ catch (error) { reject(error); }
226
+ };
227
+ }
228
+
229
+ this._promise = new Promise(_executor)
230
+ .then(_onFulfilled, _onRejected);
231
+ }
232
+
233
+ public get startTime(): number { return this._startTime; }
234
+ public get elapsedTime(): number
235
+ {
236
+ if (this._isRunning) { return Date.now() - this._startTime; }
237
+
238
+ return this._endTime! - this._startTime;
239
+ }
240
+ public get estimatedTime(): number { return this._estimatedTime; }
241
+ public get endTime(): number
242
+ {
243
+ if (this._isRunning)
244
+ {
245
+ throw new RuntimeException("The task is still running and has no end time yet.");
246
+ }
247
+
248
+ return this._endTime!;
249
+ }
250
+
251
+ public get currentStep(): number { return this._currentStep; }
252
+ public get percentage(): number { return this._percentage; }
253
+
254
+ public get isRunning(): boolean { return this._isRunning; }
255
+ public get hasCompleted(): boolean { return this._hasCompleted; }
256
+ public get hasFailed(): boolean { return this._hasFailed; }
257
+
258
+ public then(onFulfilled?: null): Promise<T>;
259
+ public then<F = T>(onFulfilled: FulfilledHandler<T, F>, onRejected?: null): Promise<F>;
260
+ public then<F = T, R = never>(onFulfilled: FulfilledHandler<T, F>, onRejected: RejectedHandler<unknown, R>)
261
+ : Promise<F | R>;
262
+ public then<F = T, R = never>(
263
+ onFulfilled?: FulfilledHandler<T, F> | null,
264
+ onRejected?: RejectedHandler<unknown, R> | null): Promise<F | R>
265
+ {
266
+ return this._promise.then(onFulfilled, onRejected);
267
+ }
268
+
269
+ public catch(onRejected?: null): Promise<T>;
270
+ public catch<R = never>(onRejected: RejectedHandler<unknown, R>): Promise<T | R>;
271
+ public catch<R = never>(onRejected?: RejectedHandler<unknown, R> | null): Promise<T | R>
272
+ {
273
+ return this._promise.catch(onRejected);
274
+ }
275
+ public finally(onFinally?: (() => void) | null): Promise<T>
276
+ {
277
+ return this._promise.finally(onFinally);
278
+ }
279
+
280
+ public onProgress(callback: () => void): () => void
281
+ {
282
+ if (!(this._publisher))
283
+ {
284
+ throw new RuntimeException(
285
+ "You cannot subscribe to progress events without enabling progress tracking. " +
286
+ "Did you forget to set the `trackProgress` option to `true` when creating the task?"
287
+ );
288
+ }
289
+
290
+ return this._publisher.subscribe("progress", callback);
291
+ }
292
+
293
+ public readonly [Symbol.toStringTag]: string = "LongRunningTask";
294
+ }
@@ -2,6 +2,11 @@ import type { FulfilledHandler, PromiseExecutor, RejectedHandler } from "./types
2
2
 
3
3
  export default class SmartPromise<T = void> implements Promise<T>
4
4
  {
5
+ public static FromPromise<T>(promise: Promise<T>): SmartPromise<T>
6
+ {
7
+ return new SmartPromise((resolve, reject) => promise.then(resolve, reject));
8
+ }
9
+
5
10
  protected _isPending: boolean;
6
11
  protected _isFulfilled: boolean;
7
12
  protected _isRejected: boolean;
@@ -59,5 +64,5 @@ export default class SmartPromise<T = void> implements Promise<T>
59
64
  return this._promise.finally(onFinally);
60
65
  }
61
66
 
62
- public get [Symbol.toStringTag]() { return "SmartPromise"; }
67
+ public readonly [Symbol.toStringTag]: string = "SmartPromise";
63
68
  }
@@ -0,0 +1,97 @@
1
+ export default class Thenable<T> implements Promise<T>
2
+ {
3
+ protected _onFulfilled: (result: T) => T;
4
+ protected _resolve(result: T): T
5
+ {
6
+ return this._onFulfilled(result);
7
+ }
8
+
9
+ public constructor()
10
+ {
11
+ this._onFulfilled = (result: T) => result;
12
+ }
13
+
14
+ public then(onFulfilled?: null): Thenable<T>;
15
+ public then<F = T>(onFulfilled: (result: T) => F, onRejected?: null): Thenable<F>;
16
+ public then<F = T, R = never>(onFulfilled: (result: T) => F, onRejected: (reason: unknown) => R)
17
+ : Thenable<F | R>;
18
+ public then<F = T, R = never>(onFulfilled?: ((result: T) => F) | null, onRejected?: ((reason: unknown) => R) | null)
19
+ : Thenable<F | R>
20
+ {
21
+ if (onRejected)
22
+ {
23
+ const _previousOnFulfilled = this._onFulfilled;
24
+ this._onFulfilled = (result: T) =>
25
+ {
26
+ try
27
+ {
28
+ result = _previousOnFulfilled(result);
29
+
30
+ return (onFulfilled!(result) as unknown) as T;
31
+ }
32
+ catch (error)
33
+ {
34
+ return (onRejected(error) as unknown) as T;
35
+ }
36
+ };
37
+ }
38
+ else if (onFulfilled)
39
+ {
40
+ const _previousOnFulfilled = this._onFulfilled;
41
+ this._onFulfilled = (result: T) =>
42
+ {
43
+ result = _previousOnFulfilled(result);
44
+
45
+ return (onFulfilled(result) as unknown) as T;
46
+ };
47
+ }
48
+
49
+ return (this as unknown) as Thenable<F | R>;
50
+ }
51
+
52
+ public catch(onRejected?: null): Thenable<T>;
53
+ public catch<R = never>(onRejected: (reason: unknown) => R): Thenable<T | R>;
54
+ public catch<R = never>(onRejected?: ((reason: unknown) => R) | null): Thenable<T | R>
55
+ {
56
+ if (onRejected)
57
+ {
58
+ const _previousOnFulfilled = this._onFulfilled;
59
+ this._onFulfilled = (result) =>
60
+ {
61
+ try
62
+ {
63
+ return _previousOnFulfilled(result);
64
+ }
65
+ catch (error)
66
+ {
67
+ return (onRejected(error) as unknown) as T;
68
+ }
69
+ };
70
+ }
71
+
72
+ return this as Thenable<T | R>;
73
+ }
74
+
75
+ public finally(onFinally?: (() => void) | null): Thenable<T>
76
+ {
77
+ if (onFinally)
78
+ {
79
+ const _previousOnFulfilled = this._onFulfilled;
80
+ this._onFulfilled = (result) =>
81
+ {
82
+ try
83
+ {
84
+ return _previousOnFulfilled(result);
85
+ }
86
+ finally
87
+ {
88
+ onFinally();
89
+ }
90
+ };
91
+ }
92
+
93
+ return this;
94
+ }
95
+
96
+ public readonly [Symbol.toStringTag]: string = "Thenable";
97
+ }
@@ -27,5 +27,5 @@ export default class TimedPromise<T = void> extends SmartPromise<T>
27
27
  });
28
28
  }
29
29
 
30
- public get [Symbol.toStringTag]() { return "TimedPromise"; }
30
+ public readonly [Symbol.toStringTag]: string = "TimedPromise";
31
31
  }
@@ -1,3 +1,5 @@
1
+ export type { LongRunningTaskOptions } from "./long-running-task.js";
2
+
1
3
  export type MaybePromise<T> = T | PromiseLike<T>;
2
4
 
3
5
  export type FulfilledHandler<T = void, R = T> = (value: T) => MaybePromise<R>;
@@ -0,0 +1,69 @@
1
+ import { TimeUnit } from "../../utils/date.js";
2
+ import { RangeException, RuntimeException } from "../exceptions/index.js";
3
+
4
+ import Publisher from "../callbacks/publisher.js";
5
+ import GameLoop from "../game-loop.js";
6
+
7
+ interface ClockEventMap
8
+ {
9
+ start: () => void;
10
+ stop: () => void;
11
+ tick: (elapsedTime: number) => void;
12
+ }
13
+
14
+ export default class Clock extends GameLoop
15
+ {
16
+ protected _publisher: Publisher<ClockEventMap>;
17
+
18
+ public constructor(msIfNotBrowser: number = TimeUnit.Second)
19
+ {
20
+ super((elapsedTime) => this._publisher.publish("tick", elapsedTime), msIfNotBrowser);
21
+
22
+ this._publisher = new Publisher();
23
+ }
24
+
25
+ public start(elapsedTime = 0): void
26
+ {
27
+ if (this._isRunning) { throw new RuntimeException("The clock has already been started."); }
28
+
29
+ super.start(elapsedTime);
30
+
31
+ this._publisher.publish("start");
32
+ }
33
+
34
+ public stop(): void
35
+ {
36
+ if (!(this._isRunning)) { throw new RuntimeException("The clock hadn't yet started."); }
37
+
38
+ super.stop();
39
+
40
+ this._publisher.publish("stop");
41
+ }
42
+
43
+ public onStart(callback: () => void): () => void
44
+ {
45
+ return this._publisher.subscribe("start", callback);
46
+ }
47
+ public onStop(callback: () => void): () => void
48
+ {
49
+ return this._publisher.subscribe("stop", callback);
50
+ }
51
+
52
+ public onTick(callback: (elapsedTime: number) => void, tickStep = 0): () => void
53
+ {
54
+ if (tickStep < 0) { throw new RangeException("The tick step must be a non-negative number."); }
55
+ if (tickStep === 0) { return this._publisher.subscribe("tick", callback); }
56
+
57
+ let lastTick = 0;
58
+
59
+ return this._publisher.subscribe("tick", (elapsedTime: number) =>
60
+ {
61
+ if ((elapsedTime - lastTick) < tickStep) { return; }
62
+
63
+ callback(elapsedTime);
64
+ lastTick = elapsedTime;
65
+ });
66
+ }
67
+
68
+ public readonly [Symbol.toStringTag]: string = "Clock";
69
+ }
@@ -0,0 +1,117 @@
1
+ import { TimeUnit } from "../../utils/date.js";
2
+
3
+ import { FatalErrorException, RangeException, RuntimeException } from "../exceptions/index.js";
4
+ import { DeferredPromise, SmartPromise } from "../promises/index.js";
5
+
6
+ import Publisher from "../callbacks/publisher.js";
7
+ import GameLoop from "../game-loop.js";
8
+
9
+ interface CountdownEventMap
10
+ {
11
+ start: () => void;
12
+ stop: (reason: unknown) => void;
13
+ tick: (remainingTime: number) => void;
14
+ expire: () => void;
15
+ }
16
+
17
+ export default class Countdown extends GameLoop
18
+ {
19
+ protected _deferrer?: DeferredPromise<void>;
20
+ protected _publisher: Publisher<CountdownEventMap>;
21
+
22
+ protected _duration: number;
23
+ public get duration(): number
24
+ {
25
+ return this._duration;
26
+ }
27
+
28
+ public get remainingTime(): number
29
+ {
30
+ return this._duration - this.elapsedTime;
31
+ }
32
+
33
+ public constructor(duration: number, msIfNotBrowser: number = TimeUnit.Second)
34
+ {
35
+ const callback = () =>
36
+ {
37
+ const remainingTime = this.remainingTime;
38
+ this._publisher.publish("tick", remainingTime);
39
+
40
+ if (remainingTime <= 0)
41
+ {
42
+ this._deferrerStop();
43
+
44
+ this._publisher.publish("expire");
45
+ }
46
+ };
47
+
48
+ super(callback, msIfNotBrowser);
49
+
50
+ this._publisher = new Publisher();
51
+ this._duration = duration;
52
+ }
53
+
54
+ protected _deferrerStop(reason?: unknown): void
55
+ {
56
+ if (!(this._isRunning)) { throw new RuntimeException("The countdown hadn't yet started."); }
57
+ if (!(this._deferrer)) { throw new FatalErrorException(); }
58
+
59
+ super.stop();
60
+
61
+ if (reason !== undefined) { this._deferrer.reject(reason); }
62
+ else { this._deferrer.resolve(); }
63
+
64
+ this._deferrer = undefined;
65
+ }
66
+
67
+ public start(remainingTime: number = this.duration): SmartPromise<void>
68
+ {
69
+ if (this._isRunning) { throw new RuntimeException("The countdown has already been started."); }
70
+ if (this._deferrer) { throw new FatalErrorException(); }
71
+
72
+ this._deferrer = new DeferredPromise();
73
+ super.start(this.duration - remainingTime);
74
+
75
+ this._publisher.publish("start");
76
+
77
+ return this._deferrer;
78
+ }
79
+ public stop(reason?: unknown): void
80
+ {
81
+ this._deferrerStop(reason);
82
+
83
+ this._publisher.publish("stop", reason);
84
+ }
85
+
86
+ public onExpire(callback: () => void): () => void
87
+ {
88
+ return this._publisher.subscribe("expire", callback);
89
+ }
90
+
91
+ public onStart(callback: () => void): () => void
92
+ {
93
+ return this._publisher.subscribe("start", callback);
94
+ }
95
+ public onStop(callback: (reason?: unknown) => void): () => void
96
+ {
97
+ return this._publisher.subscribe("stop", callback);
98
+ }
99
+
100
+ public onTick(callback: (remainingTime: number) => void, tickStep = 0): () => void
101
+ {
102
+ if (tickStep < 0) { throw new RangeException("The tick step must be a non-negative number."); }
103
+ if (tickStep === 0) { return this._publisher.subscribe("tick", callback); }
104
+
105
+ let lastTick = 0;
106
+
107
+ return this._publisher.subscribe("tick", (remainingTime: number) =>
108
+ {
109
+ if ((lastTick - remainingTime) < tickStep) { return; }
110
+
111
+ callback(remainingTime);
112
+ lastTick = remainingTime;
113
+ });
114
+ }
115
+
116
+ public readonly [Symbol.toStringTag]: string = "Countdown";
117
+ }
@@ -0,0 +1,4 @@
1
+ import Clock from "./clock.js";
2
+ import Countdown from "./countdown.js";
3
+
4
+ export { Clock, Countdown };
@@ -1,29 +1,38 @@
1
1
  export type {
2
- KeyIteratee,
3
- MaybeAsyncKeyIteratee,
4
- KeyTypeGuardIteratee,
5
- MaybeAsyncKeyTypeGuardIteratee,
6
- KeyReducer,
7
- MaybeAsyncKeyReducer
2
+ KeyedIteratee,
3
+ MaybeAsyncKeyedIteratee,
4
+ KeyedTypeGuardIteratee,
5
+ MaybeAsyncKeyedTypeGuardIteratee,
6
+ KeyedReducer,
7
+ MaybeAsyncKeyedReducer
8
8
 
9
9
  } from "./aggregators/types.js";
10
10
 
11
11
  export type {
12
12
  GeneratorFunction,
13
13
  AsyncGeneratorFunction,
14
+ MaybeAsyncGeneratorFunction,
14
15
  Iteratee,
15
16
  MaybeAsyncIteratee,
16
17
  TypeGuardIteratee,
17
18
  MaybeAsyncTypeGuardIteratee,
18
19
  Reducer,
19
20
  MaybeAsyncReducer,
20
- IterLike,
21
- AsyncIterLike,
22
- MaybeAsyncIterLike
21
+ IteratorLike,
22
+ AsyncIteratorLike,
23
+ MaybeAsyncIteratorLike
23
24
 
24
25
  } from "./iterators/types.js";
25
26
 
26
27
  export type {
28
+ JSONArray,
29
+ JSONObject,
30
+ JSONValue
31
+
32
+ } from "./json/types.js";
33
+
34
+ export type {
35
+ LongRunningTaskOptions,
27
36
  MaybePromise,
28
37
  FulfilledHandler,
29
38
  RejectedHandler,
@@ -32,3 +41,5 @@ export type {
32
41
  PromiseExecutor
33
42
 
34
43
  } from "./promises/types.js";
44
+
45
+ export type { Callback } from "./callbacks/types.js";
@@ -1,9 +1,14 @@
1
- export async function delay(milliseconds: number): Promise<void>
1
+ export function delay(milliseconds: number): Promise<void>
2
2
  {
3
- return new Promise<void>((resolve, reject) => setTimeout(resolve, milliseconds));
3
+ return new Promise((resolve) => setTimeout(resolve, milliseconds));
4
4
  }
5
5
 
6
- export async function nextAnimationFrame(): Promise<void>
6
+ export function nextAnimationFrame(): Promise<void>
7
7
  {
8
- return new Promise<void>((resolve, reject) => requestAnimationFrame(() => resolve()));
8
+ return new Promise((resolve) => requestAnimationFrame(() => resolve()));
9
+ }
10
+
11
+ export function yieldToEventLoop(): Promise<void>
12
+ {
13
+ return new Promise((resolve) => setTimeout(resolve));
9
14
  }