@handy-common-utils/promise-utils 1.6.0 → 1.7.1
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/README.md +1317 -466
- package/dist/promise-utils.d.ts +289 -22
- package/dist/promise-utils.d.ts.map +1 -1
- package/dist/promise-utils.js +386 -33
- package/dist/promise-utils.js.map +1 -0
- package/package.json +2 -2
package/dist/promise-utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.promiseState = exports.synchronised = exports.synchronized = exports.timeoutReject = exports.timeoutResolve = exports.delayedReject = exports.delayedResolve = exports.inParallel = exports.withConcurrency = exports.withRetry = exports.repeat = exports.PromiseUtils = exports.PromiseState = exports.EXPONENTIAL_SEQUENCE = exports.FIBONACCI_SEQUENCE = void 0;
|
|
3
|
+
exports.runPeriodically = exports.promiseState = exports.synchronised = exports.synchronized = exports.timeoutReject = exports.timeoutResolve = exports.cancellableDelayedReject = exports.cancellableDelayedResolve = exports.delayedReject = exports.delayedResolve = exports.inParallel = exports.withConcurrency = exports.withRetry = exports.repeat = exports.PromiseUtils = exports.PromiseState = exports.EXPONENTIAL_SEQUENCE = exports.FIBONACCI_SEQUENCE = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Array of 25 Fibonacci numbers starting from 1 up to 317811.
|
|
6
6
|
* It can be used to form your own backoff interval array.
|
|
@@ -28,12 +28,11 @@ exports.EXPONENTIAL_SEQUENCE = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 204
|
|
|
28
28
|
/**
|
|
29
29
|
* The state of a Promise can only be one of: Pending, Fulfilled, and Rejected.
|
|
30
30
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
})(PromiseState || (exports.PromiseState = PromiseState = {}));
|
|
31
|
+
exports.PromiseState = {
|
|
32
|
+
Pending: 'Pending',
|
|
33
|
+
Fulfilled: 'Fulfilled',
|
|
34
|
+
Rejected: 'Rejected',
|
|
35
|
+
};
|
|
37
36
|
class PromiseUtils {
|
|
38
37
|
/**
|
|
39
38
|
* Executes an operation repeatedly and collects all the results.
|
|
@@ -205,31 +204,120 @@ class PromiseUtils {
|
|
|
205
204
|
await Promise.all(promises);
|
|
206
205
|
return jobResults;
|
|
207
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* Creates a cancellable timer that will resolve after a specified number of milliseconds.
|
|
209
|
+
*
|
|
210
|
+
* The returned object contains:
|
|
211
|
+
* - `stop()` to cancel the scheduled resolution (if called before the timer fires). Calling
|
|
212
|
+
* `stop()` prevents the promise from being settled by this timer.
|
|
213
|
+
* - `promise` which will resolve with the supplied `result` (or the value returned by the
|
|
214
|
+
* `result` function) after `ms` milliseconds unless `stop()` is called first.
|
|
215
|
+
*
|
|
216
|
+
* Note: If the `result` is a function that returns a Promise, the returned `promise` will
|
|
217
|
+
* resolve with that Promise's resolution (i.e. it behaves like resolving with a PromiseLike).
|
|
218
|
+
*
|
|
219
|
+
* @param ms The number of milliseconds after which the scheduled resolution will occur.
|
|
220
|
+
* @param result The result to be resolved by the Promise, or a function that supplies the result.
|
|
221
|
+
* @returns An object with `stop()` and `promise`.
|
|
222
|
+
*/
|
|
223
|
+
static cancellableDelayedResolve(ms, result) {
|
|
224
|
+
let stopped = false;
|
|
225
|
+
let timer;
|
|
226
|
+
const promise = new Promise(resolve => {
|
|
227
|
+
timer = setTimeout(() => {
|
|
228
|
+
timer = undefined;
|
|
229
|
+
if (stopped)
|
|
230
|
+
return;
|
|
231
|
+
resolve(typeof result === 'function' ? result() : result);
|
|
232
|
+
}, ms);
|
|
233
|
+
});
|
|
234
|
+
const stop = () => {
|
|
235
|
+
if (stopped)
|
|
236
|
+
return;
|
|
237
|
+
stopped = true;
|
|
238
|
+
if (timer !== undefined) {
|
|
239
|
+
clearTimeout(timer);
|
|
240
|
+
timer = undefined;
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
return { stop, promise };
|
|
244
|
+
}
|
|
208
245
|
/**
|
|
209
246
|
* Creates a Promise that resolves after a specified number of milliseconds.
|
|
210
247
|
*
|
|
248
|
+
* The `result` argument may be:
|
|
249
|
+
* - a value to resolve with,
|
|
250
|
+
* - a PromiseLike whose resolution will be adopted by the returned Promise, or
|
|
251
|
+
* - a function which is invoked when the timer fires and may return a value or a PromiseLike.
|
|
252
|
+
*
|
|
253
|
+
* If `result` is a function, it is called when the timer elapses; if it returns a Promise,
|
|
254
|
+
* the returned Promise will adopt that Promise's outcome.
|
|
255
|
+
*
|
|
211
256
|
* @param ms The number of milliseconds after which the created Promise will resolve.
|
|
212
257
|
* @param result The result to be resolved by the Promise, or a function that supplies the result.
|
|
213
|
-
* @returns A
|
|
258
|
+
* @returns A Promise that resolves with the specified result after the specified delay.
|
|
214
259
|
*/
|
|
215
260
|
static delayedResolve(ms, result) {
|
|
216
|
-
|
|
217
|
-
|
|
261
|
+
return PromiseUtils.cancellableDelayedResolve(ms, result).promise;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Creates a cancellable timer that will reject after a specified number of milliseconds.
|
|
265
|
+
*
|
|
266
|
+
* The returned object contains:
|
|
267
|
+
* - `stop()` to cancel the scheduled rejection (if called before the timer fires). Calling
|
|
268
|
+
* `stop()` prevents the promise from being settled by this timer.
|
|
269
|
+
* - `promise` which will reject with the supplied `reason` (or the value returned by the
|
|
270
|
+
* `reason` function) after `ms` milliseconds unless `stop()` is called first.
|
|
271
|
+
*
|
|
272
|
+
* If the `reason` is a PromiseLike that rejects, its rejection value will be used as the rejection reason.
|
|
273
|
+
*
|
|
274
|
+
* @param ms The number of milliseconds after which the scheduled rejection will occur.
|
|
275
|
+
* @param reason The reason for the rejection, or a function that supplies the reason.
|
|
276
|
+
* @returns An object with `stop()` and `promise`.
|
|
277
|
+
*/
|
|
278
|
+
static cancellableDelayedReject(ms, reason) {
|
|
279
|
+
let stopped = false;
|
|
280
|
+
let timer;
|
|
281
|
+
const promise = new Promise((_resolve, reject) => {
|
|
282
|
+
timer = setTimeout(() => {
|
|
283
|
+
timer = undefined;
|
|
284
|
+
if (stopped)
|
|
285
|
+
return;
|
|
286
|
+
const r = typeof reason === 'function' ? reason() : reason;
|
|
287
|
+
// Resolve the possibly-PromiseLike `r` and reject the outer promise with either
|
|
288
|
+
// the resolved value or the rejection reason of `r`.
|
|
289
|
+
Promise.resolve(r).then(reject, reject);
|
|
290
|
+
}, ms);
|
|
291
|
+
});
|
|
292
|
+
const stop = () => {
|
|
293
|
+
if (stopped)
|
|
294
|
+
return;
|
|
295
|
+
stopped = true;
|
|
296
|
+
if (timer !== undefined) {
|
|
297
|
+
clearTimeout(timer);
|
|
298
|
+
timer = undefined;
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
return { stop, promise };
|
|
218
302
|
}
|
|
219
303
|
/**
|
|
220
304
|
* Creates a Promise that rejects after a specified number of milliseconds.
|
|
221
305
|
*
|
|
306
|
+
* The `reason` argument may be:
|
|
307
|
+
* - a value to reject with,
|
|
308
|
+
* - a PromiseLike whose rejection will be adopted by the returned Promise, or
|
|
309
|
+
* - a function which is invoked when the timer fires and may return a value or a PromiseLike.
|
|
310
|
+
*
|
|
311
|
+
* If `reason` is a function, it is called when the timer elapses; if it returns a Promise,
|
|
312
|
+
* the returned Promise will reject with that Promise's rejection reason (or reject with the
|
|
313
|
+
* returned value if it resolves).
|
|
314
|
+
*
|
|
222
315
|
* @param ms The number of milliseconds after which the created Promise will reject.
|
|
223
316
|
* @param reason The reason for the rejection, or a function that supplies the reason.
|
|
224
|
-
*
|
|
225
|
-
* @returns A new Promise that rejects with the specified reason after the specified delay.
|
|
317
|
+
* @returns A Promise that rejects with the specified reason after the specified delay.
|
|
226
318
|
*/
|
|
227
319
|
static delayedReject(ms, reason) {
|
|
228
|
-
|
|
229
|
-
return new Promise((_resolve, reject) => setTimeout(() => {
|
|
230
|
-
const r = typeof reason === 'function' ? reason() : reason;
|
|
231
|
-
Promise.resolve(r).catch(error => error).then(r => reject(r));
|
|
232
|
-
}, ms));
|
|
320
|
+
return PromiseUtils.cancellableDelayedReject(ms, reason).promise;
|
|
233
321
|
}
|
|
234
322
|
/**
|
|
235
323
|
* Applies a timeout to a Promise or a function that returns a Promise.
|
|
@@ -249,7 +337,7 @@ class PromiseUtils {
|
|
|
249
337
|
return Promise.race([
|
|
250
338
|
promise,
|
|
251
339
|
PromiseUtils.delayedResolve(ms, () => PromiseUtils.promiseState(promise)
|
|
252
|
-
.then(state => state === PromiseState.Pending ?
|
|
340
|
+
.then(state => state === exports.PromiseState.Pending ?
|
|
253
341
|
(typeof result === 'function' ? result() : result) :
|
|
254
342
|
{})),
|
|
255
343
|
]);
|
|
@@ -271,7 +359,7 @@ class PromiseUtils {
|
|
|
271
359
|
return Promise.race([
|
|
272
360
|
promise,
|
|
273
361
|
PromiseUtils.delayedReject(ms, () => PromiseUtils.promiseState(promise)
|
|
274
|
-
.then(state => state === PromiseState.Pending ?
|
|
362
|
+
.then(state => state === exports.PromiseState.Pending ?
|
|
275
363
|
(typeof rejectReason === 'function' ? rejectReason() : rejectReason) :
|
|
276
364
|
{})),
|
|
277
365
|
]);
|
|
@@ -286,7 +374,7 @@ class PromiseUtils {
|
|
|
286
374
|
static promiseState(p) {
|
|
287
375
|
const t = {};
|
|
288
376
|
return Promise.race([p, t])
|
|
289
|
-
.then(v => (v === t) ? PromiseState.Pending : PromiseState.Fulfilled, () => PromiseState.Rejected);
|
|
377
|
+
.then(v => (v === t) ? exports.PromiseState.Pending : exports.PromiseState.Fulfilled, () => exports.PromiseState.Rejected);
|
|
290
378
|
}
|
|
291
379
|
/**
|
|
292
380
|
* Provides mutual exclusion similar to `synchronized` in Java.
|
|
@@ -308,8 +396,8 @@ class PromiseUtils {
|
|
|
308
396
|
previousState = await PromiseUtils.promiseState(previousResultPromise);
|
|
309
397
|
}
|
|
310
398
|
switch (previousState) {
|
|
311
|
-
case PromiseState.Pending: { // concurrency
|
|
312
|
-
resultPromise = previousResultPromise.then(result => operation(PromiseState.Pending, PromiseState.Fulfilled, result), error => operation(PromiseState.Pending, PromiseState.Rejected, error));
|
|
399
|
+
case exports.PromiseState.Pending: { // concurrency
|
|
400
|
+
resultPromise = previousResultPromise.then(result => operation(exports.PromiseState.Pending, exports.PromiseState.Fulfilled, result), error => operation(exports.PromiseState.Pending, exports.PromiseState.Rejected, error));
|
|
313
401
|
break;
|
|
314
402
|
}
|
|
315
403
|
case undefined: { // no concurrency and no history
|
|
@@ -334,50 +422,315 @@ class PromiseUtils {
|
|
|
334
422
|
static async synchronised(lock, operation) {
|
|
335
423
|
return PromiseUtils.synchronized(lock, operation);
|
|
336
424
|
}
|
|
425
|
+
/**
|
|
426
|
+
* Runs an operation periodically with configurable intervals and stopping conditions.
|
|
427
|
+
*
|
|
428
|
+
* - `interval` may be a single number (ms), an array of numbers, or a function
|
|
429
|
+
* that receives the iteration number (starting at 1) and returns the next
|
|
430
|
+
* interval in milliseconds or `undefined` to stop.
|
|
431
|
+
* - If the interval array runs out of elements or the function returns `undefined`
|
|
432
|
+
* (or a negative value), no further invocations will be scheduled.
|
|
433
|
+
*
|
|
434
|
+
* Options:
|
|
435
|
+
* - `maxExecutions` stop after N runs (inclusive).
|
|
436
|
+
* - `maxDurationMs` stop after elapsed ms since the first scheduled start.
|
|
437
|
+
* - `schedule` controls how the interval is measured:
|
|
438
|
+
* - `'delayAfterEnd'`: wait the interval after the previous operation completes
|
|
439
|
+
* before scheduling the next one (equivalent to a fixed delay between ends).
|
|
440
|
+
* - `'delayBetweenStarts'`: keep start times on a regular schedule (interval measured
|
|
441
|
+
* between the starts of successive operations).
|
|
442
|
+
* The default schedule is `'delayBetweenStarts'`.
|
|
443
|
+
*
|
|
444
|
+
* Returns an object with `stop()` to cancel further executions and `done` which
|
|
445
|
+
* resolves when the periodic runner stops. If the provided `operation` throws or
|
|
446
|
+
* rejects, the `done` promise will reject with that error so callers can handle it.
|
|
447
|
+
*
|
|
448
|
+
* Note: The first invocation of `operation` is scheduled after the first interval
|
|
449
|
+
* elapses (i.e. this function does NOT call `operation` immediately). If you need
|
|
450
|
+
* an immediate run, invoke `operation(1)` yourself before calling `runPeriodically`.
|
|
451
|
+
*
|
|
452
|
+
* @template T The operation return type (ignored by the runner; used for typing).
|
|
453
|
+
* @param operation Function to run each iteration. Receives the iteration index (1-based).
|
|
454
|
+
* @param interval Number | number[] | ((iteration: number) => number|undefined) defining waits.
|
|
455
|
+
* @param options Optional configuration.
|
|
456
|
+
* @param options.maxExecutions Stop after N executions.
|
|
457
|
+
* @param options.maxDurationMs Stop after N milliseconds.
|
|
458
|
+
* @param options.schedule How to measure intervals: `'delayAfterEnd'` or `'delayBetweenStarts'`.
|
|
459
|
+
* @returns An object containing `stop()` to cancel further executions and `done` Promise
|
|
460
|
+
* which resolves when the periodic runner stops (or rejects if the operation errors).
|
|
461
|
+
*/
|
|
462
|
+
static runPeriodically(operation, interval, options) {
|
|
463
|
+
let stopped = false;
|
|
464
|
+
let timer;
|
|
465
|
+
let waitResolve;
|
|
466
|
+
const stop = () => {
|
|
467
|
+
stopped = true;
|
|
468
|
+
if (timer !== undefined) {
|
|
469
|
+
clearTimeout(timer);
|
|
470
|
+
timer = undefined;
|
|
471
|
+
}
|
|
472
|
+
if (waitResolve) {
|
|
473
|
+
// resolve the pending wait so the runner can notice `stopped` and exit
|
|
474
|
+
const r = waitResolve;
|
|
475
|
+
waitResolve = undefined;
|
|
476
|
+
r();
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
const getInterval = (iteration) => {
|
|
480
|
+
if (Array.isArray(interval)) {
|
|
481
|
+
return interval[iteration - 1];
|
|
482
|
+
}
|
|
483
|
+
if (typeof interval === 'function') {
|
|
484
|
+
return interval(iteration);
|
|
485
|
+
}
|
|
486
|
+
return interval;
|
|
487
|
+
};
|
|
488
|
+
const done = (async () => {
|
|
489
|
+
var _a;
|
|
490
|
+
const startTime = Date.now();
|
|
491
|
+
let iteration = 0;
|
|
492
|
+
// lastStart tracks the start time of the previous iteration (used by delayBetweenStarts)
|
|
493
|
+
let lastStart = Date.now();
|
|
494
|
+
while (!stopped) {
|
|
495
|
+
const nextIteration = iteration + 1;
|
|
496
|
+
const nextInterval = getInterval(nextIteration);
|
|
497
|
+
if (nextInterval == null || nextInterval < 0)
|
|
498
|
+
break;
|
|
499
|
+
const schedule = (_a = options === null || options === void 0 ? void 0 : options.schedule) !== null && _a !== void 0 ? _a : 'delayBetweenStarts';
|
|
500
|
+
const waitMs = schedule === 'delayBetweenStarts'
|
|
501
|
+
? Math.max(0, lastStart + nextInterval - Date.now())
|
|
502
|
+
: nextInterval;
|
|
503
|
+
// wait (cancelable via stop() which clears the timeout and resolves the wait)
|
|
504
|
+
await new Promise(resolve => {
|
|
505
|
+
waitResolve = resolve;
|
|
506
|
+
timer = setTimeout(() => { timer = undefined; waitResolve = undefined; resolve(); }, waitMs);
|
|
507
|
+
});
|
|
508
|
+
waitResolve = undefined;
|
|
509
|
+
if (stopped)
|
|
510
|
+
break;
|
|
511
|
+
iteration = nextIteration;
|
|
512
|
+
lastStart = Date.now();
|
|
513
|
+
// let errors propagate to the done promise so caller can decide handling
|
|
514
|
+
await operation(iteration);
|
|
515
|
+
if ((options === null || options === void 0 ? void 0 : options.maxExecutions) && iteration >= options.maxExecutions)
|
|
516
|
+
break;
|
|
517
|
+
if ((options === null || options === void 0 ? void 0 : options.maxDurationMs) && (Date.now() - startTime) >= options.maxDurationMs)
|
|
518
|
+
break;
|
|
519
|
+
}
|
|
520
|
+
})();
|
|
521
|
+
return { stop, done };
|
|
522
|
+
}
|
|
337
523
|
}
|
|
338
524
|
exports.PromiseUtils = PromiseUtils;
|
|
339
525
|
PromiseUtils.synchronizationLocks = new Map();
|
|
340
526
|
/**
|
|
341
|
-
*
|
|
527
|
+
* Executes an operation repeatedly and collects all the results.
|
|
528
|
+
* This function is very useful for many scenarios, such like client-side pagination.
|
|
529
|
+
*
|
|
530
|
+
* @param operation A function that takes a parameter as input and returns a result. Typically, the parameter has optional fields to control paging.
|
|
531
|
+
* @param nextParameter A function for calculating the next parameter from the operation result. Normally, this parameter controls paging. This function should return null when no further invocation of the operation function is desired. If further invocation is desired, the return value of this function can be a Promise or a non-Promise value.
|
|
532
|
+
* @param collect A function for merging the operation result into the collection.
|
|
533
|
+
* @param initialCollection The initial collection, which will be the first argument passed to the first invocation of the collect function.
|
|
534
|
+
* @param initialParameter The parameter for the first operation.
|
|
535
|
+
* @returns A promise that resolves to a collection of all the results returned by the operation function.
|
|
342
536
|
*/
|
|
343
537
|
exports.repeat = PromiseUtils.repeat;
|
|
344
538
|
/**
|
|
345
|
-
*
|
|
539
|
+
* Repeatedly performs an operation until a specified criteria is met.
|
|
540
|
+
*
|
|
541
|
+
* @param operation A function that outputs a Promise result. Typically, the operation does not use its arguments.
|
|
542
|
+
* @param backoff An array of retry backoff periods (in milliseconds) or a function for calculating them.
|
|
543
|
+
* @param shouldRetry A predicate function for deciding whether another call to the operation should occur.
|
|
544
|
+
* @returns A promise of the operation result, potentially with retries applied.
|
|
346
545
|
*/
|
|
347
546
|
exports.withRetry = PromiseUtils.withRetry;
|
|
348
547
|
/**
|
|
349
|
-
*
|
|
548
|
+
* Executes multiple jobs/operations with a specified level of concurrency.
|
|
549
|
+
*
|
|
550
|
+
* @param concurrency The number of jobs/operations to run concurrently.
|
|
551
|
+
* @param jobs The job data to be processed. This function can handle an infinite or unknown number of elements safely.
|
|
552
|
+
* @param operation The function that processes job data asynchronously.
|
|
553
|
+
* @returns A promise that resolves to an array containing the results from the operation function.
|
|
554
|
+
* The results in the returned array are in the same order as the corresponding elements in the jobs array.
|
|
350
555
|
*/
|
|
351
556
|
exports.withConcurrency = PromiseUtils.withConcurrency;
|
|
352
557
|
/**
|
|
353
|
-
*
|
|
558
|
+
* Executes multiple jobs/operations in parallel. By default, all operations are executed regardless of any failures.
|
|
559
|
+
* In most cases, using withConcurrency might be more convenient.
|
|
560
|
+
*
|
|
561
|
+
* By default, this function does not throw or reject an error when any job/operation fails.
|
|
562
|
+
* Errors from operations are returned alongside results in the returned array.
|
|
563
|
+
* This function only resolves when all jobs/operations are settled (either resolved or rejected).
|
|
564
|
+
*
|
|
565
|
+
* If options.abortOnError is set to true, this function throws (or rejects with) an error immediately when any job/operation fails.
|
|
566
|
+
* In this mode, some jobs/operations may not be executed if one fails.
|
|
567
|
+
*
|
|
568
|
+
* @param parallelism The number of jobs/operations to run concurrently.
|
|
569
|
+
* @param jobs The job data to be processed. This function can safely handle an infinite or unknown number of elements.
|
|
570
|
+
* @param operation The function that processes job data asynchronously.
|
|
571
|
+
* @param options Options to control the function's behavior.
|
|
572
|
+
* @param options.abortOnError If true, the function aborts and throws an error on the first failed operation.
|
|
573
|
+
* @returns A promise that resolves to an array containing the results of the operations.
|
|
574
|
+
* Each element is either a fulfilled result or a rejected error/reason.
|
|
575
|
+
* The results or errors in the returned array are in the same order as the corresponding elements in the jobs array.
|
|
354
576
|
*/
|
|
355
577
|
exports.inParallel = PromiseUtils.inParallel;
|
|
356
578
|
/**
|
|
357
|
-
*
|
|
579
|
+
* Creates a Promise that resolves after a specified number of milliseconds.
|
|
580
|
+
*
|
|
581
|
+
* The result argument may be:
|
|
582
|
+
* - a value to resolve with,
|
|
583
|
+
* - a PromiseLike whose resolution will be adopted by the returned Promise, or
|
|
584
|
+
* - a function which is invoked when the timer fires and may return a value or a PromiseLike.
|
|
585
|
+
*
|
|
586
|
+
* If result is a function, it is called when the timer elapses; if it returns a Promise,
|
|
587
|
+
* the returned Promise will adopt that Promise's outcome.
|
|
588
|
+
*
|
|
589
|
+
* @param ms The number of milliseconds after which the created Promise will resolve.
|
|
590
|
+
* @param result The result to be resolved by the Promise, or a function that supplies the result.
|
|
591
|
+
* @returns A Promise that resolves with the specified result after the specified delay.
|
|
358
592
|
*/
|
|
359
593
|
exports.delayedResolve = PromiseUtils.delayedResolve;
|
|
360
594
|
/**
|
|
361
|
-
*
|
|
595
|
+
* Creates a Promise that rejects after a specified number of milliseconds.
|
|
596
|
+
*
|
|
597
|
+
* The reason argument may be:
|
|
598
|
+
* - a value to reject with,
|
|
599
|
+
* - a PromiseLike whose rejection will be adopted by the returned Promise, or
|
|
600
|
+
* - a function which is invoked when the timer fires and may return a value or a PromiseLike.
|
|
601
|
+
*
|
|
602
|
+
* If reason is a function, it is called when the timer elapses; if it returns a Promise,
|
|
603
|
+
* the returned Promise will reject with that Promise's rejection reason (or reject with the
|
|
604
|
+
* returned value if it resolves).
|
|
605
|
+
*
|
|
606
|
+
* @param ms The number of milliseconds after which the created Promise will reject.
|
|
607
|
+
* @param reason The reason for the rejection, or a function that supplies the reason.
|
|
608
|
+
* @returns A Promise that rejects with the specified reason after the specified delay.
|
|
362
609
|
*/
|
|
363
610
|
exports.delayedReject = PromiseUtils.delayedReject;
|
|
364
611
|
/**
|
|
365
|
-
*
|
|
612
|
+
* Creates a cancellable timer that will resolve after a specified number of milliseconds.
|
|
613
|
+
*
|
|
614
|
+
* The returned object contains:
|
|
615
|
+
* - stop() to cancel the scheduled resolution (if called before the timer fires). Calling
|
|
616
|
+
* stop() prevents the promise from being settled by this timer.
|
|
617
|
+
* - promise which will resolve with the supplied result (or the value returned by the
|
|
618
|
+
* result function) after ms milliseconds unless stop() is called first.
|
|
619
|
+
*
|
|
620
|
+
* If the result is a PromiseLike, its resolution value will be used as the resolved value.
|
|
621
|
+
*
|
|
622
|
+
* @param ms The number of milliseconds after which the scheduled resolution will occur.
|
|
623
|
+
* @param result The result to be resolved by the Promise, or a function that supplies the result.
|
|
624
|
+
* @returns An object with stop() and promise.
|
|
625
|
+
*/
|
|
626
|
+
exports.cancellableDelayedResolve = PromiseUtils.cancellableDelayedResolve;
|
|
627
|
+
/**
|
|
628
|
+
* Creates a cancellable timer that will reject after a specified number of milliseconds.
|
|
629
|
+
*
|
|
630
|
+
* The returned object contains:
|
|
631
|
+
* - stop() to cancel the scheduled rejection (if called before the timer fires). Calling
|
|
632
|
+
* stop() prevents the promise from being settled by this timer.
|
|
633
|
+
* - promise which will reject with the supplied reason (or the value returned by the
|
|
634
|
+
* reason function) after ms milliseconds unless stop() is called first.
|
|
635
|
+
*
|
|
636
|
+
* If the reason is a PromiseLike that rejects, its rejection value will be used as the rejection reason.
|
|
637
|
+
*
|
|
638
|
+
* @param ms The number of milliseconds after which the scheduled rejection will occur.
|
|
639
|
+
* @param reason The reason for the rejection, or a function that supplies the reason.
|
|
640
|
+
* @returns An object with stop() and promise.
|
|
641
|
+
*/
|
|
642
|
+
exports.cancellableDelayedReject = PromiseUtils.cancellableDelayedReject;
|
|
643
|
+
/**
|
|
644
|
+
* Applies a timeout to a Promise or a function that returns a Promise.
|
|
645
|
+
* If the timeout occurs, the returned Promise resolves to the specified result.
|
|
646
|
+
* If the timeout does not occur, the returned Promise resolves or rejects based on the outcome of the original Promise.
|
|
647
|
+
* If the result parameter is a function and the timeout does not occur, the function will not be called.
|
|
648
|
+
* Note: The rejection of the operation parameter is not handled by this function.
|
|
649
|
+
* You may want to handle it outside this function to avoid warnings like "(node:4330) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously."
|
|
650
|
+
*
|
|
651
|
+
* @param operation The original Promise or a function that returns a Promise to which the timeout will be applied.
|
|
652
|
+
* @param ms The number of milliseconds for the timeout.
|
|
653
|
+
* @param result The result to resolve with if the timeout occurs, or a function that supplies the result.
|
|
654
|
+
* @returns A new Promise that resolves to the specified result if the timeout occurs.
|
|
366
655
|
*/
|
|
367
656
|
exports.timeoutResolve = PromiseUtils.timeoutResolve;
|
|
368
657
|
/**
|
|
369
|
-
*
|
|
658
|
+
* Applies a timeout to a Promise or a function that returns a Promise.
|
|
659
|
+
* If the timeout occurs, the returned Promise rejects with the specified reason.
|
|
660
|
+
* If the timeout does not occur, the returned Promise resolves or rejects based on the outcome of the original Promise.
|
|
661
|
+
* If the rejectReason parameter is a function and the timeout does not occur, the function will not be called.
|
|
662
|
+
* Note: The rejection of the operation parameter is not handled by this function. You may want to handle it outside this function to avoid warnings like "(node:4330) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously."
|
|
663
|
+
*
|
|
664
|
+
* @param operation The original Promise or a function that returns a Promise to which the timeout will be applied.
|
|
665
|
+
* @param ms The number of milliseconds for the timeout.
|
|
666
|
+
* @param rejectReason The reason to reject with if the timeout occurs, or a function that supplies the reason.
|
|
667
|
+
* @returns A new Promise that rejects with the specified reason if the timeout occurs.
|
|
370
668
|
*/
|
|
371
669
|
exports.timeoutReject = PromiseUtils.timeoutReject;
|
|
372
670
|
/**
|
|
373
|
-
*
|
|
671
|
+
* Provides mutual exclusion similar to synchronized in Java.
|
|
672
|
+
* Ensures no concurrent execution of any operation function associated with the same lock.
|
|
673
|
+
* The operation function has access to the state (when synchronized is called),
|
|
674
|
+
* settledState (when the operation function is called),
|
|
675
|
+
* and result (either the fulfilled result or the rejected reason) of the previous operation.
|
|
676
|
+
* If there is no previous invocation, state, settledState, and result will all be undefined.
|
|
677
|
+
*
|
|
678
|
+
* @param lock The object (such as a string, a number, or this in a class) used to identify the lock.
|
|
679
|
+
* @param operation The function that performs the computation and returns a Promise.
|
|
680
|
+
* @returns The result of the operation function.
|
|
374
681
|
*/
|
|
375
682
|
exports.synchronized = PromiseUtils.synchronized;
|
|
376
683
|
/**
|
|
377
|
-
*
|
|
684
|
+
* This is just another spelling of synchronized.
|
|
685
|
+
* @param lock The object (such as a string, a number, or this in a class) used to identify the lock.
|
|
686
|
+
* @param operation The function that performs the computation and returns a Promise.
|
|
687
|
+
* @returns The result of the operation function.
|
|
378
688
|
*/
|
|
379
689
|
exports.synchronised = PromiseUtils.synchronised;
|
|
380
690
|
/**
|
|
381
|
-
*
|
|
691
|
+
* Retrieves the state of the specified Promise.
|
|
692
|
+
* Note: The returned value is a Promise that resolves immediately.
|
|
693
|
+
*
|
|
694
|
+
* @param p The Promise whose state is to be determined.
|
|
695
|
+
* @returns A Promise that resolves immediately with the state of the input Promise.
|
|
382
696
|
*/
|
|
383
697
|
exports.promiseState = PromiseUtils.promiseState;
|
|
698
|
+
/**
|
|
699
|
+
* Runs an operation periodically with configurable intervals and stopping conditions.
|
|
700
|
+
*
|
|
701
|
+
* - `interval` may be a single number (ms), an array of numbers, or a function
|
|
702
|
+
* that receives the iteration number (starting at 1) and returns the next
|
|
703
|
+
* interval in milliseconds or `undefined` to stop.
|
|
704
|
+
* - If the interval array runs out of elements or the function returns `undefined`
|
|
705
|
+
* (or a negative value), no further invocations will be scheduled.
|
|
706
|
+
*
|
|
707
|
+
* Options:
|
|
708
|
+
* - `maxExecutions` stop after N runs (inclusive).
|
|
709
|
+
* - `maxDurationMs` stop after elapsed ms since the first scheduled start.
|
|
710
|
+
* - `schedule` controls how the interval is measured:
|
|
711
|
+
* - `'delayAfterEnd'`: wait the interval after the previous operation completes
|
|
712
|
+
* before scheduling the next one (equivalent to a fixed delay between ends).
|
|
713
|
+
* - `'delayBetweenStarts'`: keep start times on a regular schedule (interval measured
|
|
714
|
+
* between the starts of successive operations).
|
|
715
|
+
* The default schedule is `'delayBetweenStarts'`.
|
|
716
|
+
*
|
|
717
|
+
* Returns an object with `stop()` to cancel further executions and `done` which
|
|
718
|
+
* resolves when the periodic runner stops. If the provided `operation` throws or
|
|
719
|
+
* rejects, the `done` promise will reject with that error so callers can handle it.
|
|
720
|
+
*
|
|
721
|
+
* Note: The first invocation of `operation` is scheduled after the first interval
|
|
722
|
+
* elapses (i.e. this function does NOT call `operation` immediately). If you need
|
|
723
|
+
* an immediate run, invoke `operation(1)` yourself before calling `runPeriodically`.
|
|
724
|
+
*
|
|
725
|
+
* @template T The operation return type (ignored by the runner; used for typing).
|
|
726
|
+
* @param operation Function to run each iteration. Receives the iteration index (1-based).
|
|
727
|
+
* @param interval Number | number[] | ((iteration: number) => number|undefined) defining waits.
|
|
728
|
+
* @param options Optional configuration.
|
|
729
|
+
* @param options.maxExecutions Stop after N executions.
|
|
730
|
+
* @param options.maxDurationMs Stop after N milliseconds.
|
|
731
|
+
* @param options.schedule How to measure intervals: `'delayAfterEnd'` or `'delayBetweenStarts'`.
|
|
732
|
+
* @returns An object containing `stop()` to cancel further executions and `done` Promise
|
|
733
|
+
* which resolves when the periodic runner stops (or rejects if the operation errors).
|
|
734
|
+
*/
|
|
735
|
+
exports.runPeriodically = PromiseUtils.runPeriodically;
|
|
736
|
+
//# sourceMappingURL=promise-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promise-utils.js","sourceRoot":"","sources":["../src/promise-utils.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;GAUG;AACU,QAAA,kBAAkB,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAElL;;;;;;;;;;GAUG;AACU,QAAA,oBAAoB,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAE/M;;GAEG;AACU,QAAA,YAAY,GAAG;IAC1B,OAAO,EAAE,SAAS;IAClB,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,UAAU;CACZ,CAAC;AAIX,M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AA,eAAe,GAAG,YAAY,CAAC,eAAe,CAAC;AAC5D;;;;;;;;;;;;;;;;;;;GAmBG;AACU,QAAA,UAAU,GAAG,YAAY,CAAC,UAAU,CAAC;AAClD;;;;;;;;;;;;;;GAcG;AACU,QAAA,cAAc,GAAG,YAAY,CAAC,cAAc,CAAC;AAC1D;;;;;;;;;;;;;;;GAeG;AACU,QAAA,aAAa,GAAG,YAAY,CAAC,aAAa,CAAC;AACxD;;;;;;;;;;;;;;GAcG;AACU,QAAA,yBAAyB,GAAG,YAAY,CAAC,yBAAyB,CAAC;AAChF;;;;;;;;;;;;;;GAcG;AACU,QAAA,wBAAwB,GAAG,YAAY,CAAC,wBAAwB,CAAC;AAC9E;;;;;;;;;;;;GAYG;AACU,QAAA,cAAc,GAAG,YAAY,CAAC,cAAc,CAAC;AAC1D;;;;;;;;;;;GAWG;AACU,QAAA,aAAa,GAAG,YAAY,CAAC,aAAa,CAAC;AACxD;;;;;;;;;;;GAWG;AACU,QAAA,YAAY,GAAG,YAAY,CAAC,YAAY,CAAC;AACtD;;;;;GAKG;AACU,QAAA,YAAY,GAAG,YAAY,CAAC,YAAY,CAAC;AACtD;;;;;;GAMG;AACU,QAAA,YAAY,GAAG,YAAY,CAAC,YAAY,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACU,QAAA,eAAe,GAAG,YAAY,CAAC,eAAe,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@handy-common-utils/promise-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"description": "Promise related utilities",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"pretest": "eslint . --ext .ts",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"types": "dist/promise-utils.d.ts",
|
|
17
17
|
"bin": {},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@handy-common-utils/dev-dependencies-mocha": "^1.
|
|
19
|
+
"@handy-common-utils/dev-dependencies-mocha": "^1.10.1",
|
|
20
20
|
"@types/node": "^18.17.1"
|
|
21
21
|
},
|
|
22
22
|
"publishConfig": {
|