@jdsalasc/solvejs-async 1.5.0
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 +38 -0
- package/dist/cjs/index.cjs +191 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/esm/index.d.ts +65 -0
- package/dist/esm/index.js +183 -0
- package/dist/esm/index.js.map +1 -0
- package/package.json +56 -0
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# @jdsalasc/solvejs-async
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@jdsalasc/solvejs-async)
|
|
4
|
+
[](https://www.npmjs.com/package/@jdsalasc/solvejs-async)
|
|
5
|
+
|
|
6
|
+
Zero-dependency async/concurrency utilities for JavaScript and TypeScript.
|
|
7
|
+
|
|
8
|
+
## Utilities
|
|
9
|
+
|
|
10
|
+
- `sleep`
|
|
11
|
+
- `timeout`
|
|
12
|
+
- `retry`
|
|
13
|
+
- `pMap`
|
|
14
|
+
- `debouncePromise`
|
|
15
|
+
- `throttlePromise`
|
|
16
|
+
|
|
17
|
+
## When to use this package
|
|
18
|
+
|
|
19
|
+
Use it when you need predictable retry logic, promise time limits, and controlled async concurrency without adding heavy helper libraries.
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm i @jdsalasc/solvejs-async
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Quick example
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { retry, timeout, pMap } from "@jdsalasc/solvejs-async";
|
|
31
|
+
|
|
32
|
+
const data = await retry(
|
|
33
|
+
() => timeout(fetch("https://api.example.com/items").then((r) => r.json()), 3000),
|
|
34
|
+
{ retries: 2, delayMs: 200, backoffFactor: 2 }
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const ids = await pMap(data.items, async (item) => item.id, { concurrency: 4 });
|
|
38
|
+
```
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sleep = sleep;
|
|
4
|
+
exports.timeout = timeout;
|
|
5
|
+
exports.retry = retry;
|
|
6
|
+
exports.pMap = pMap;
|
|
7
|
+
exports.debouncePromise = debouncePromise;
|
|
8
|
+
exports.throttlePromise = throttlePromise;
|
|
9
|
+
function assertNonNegativeFinite(value, label) {
|
|
10
|
+
if (!Number.isFinite(value) || value < 0) {
|
|
11
|
+
throw new TypeError(`Expected ${label} to be a non-negative finite number.`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function assertPositiveInteger(value, label) {
|
|
15
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
16
|
+
throw new TypeError(`Expected ${label} to be a positive integer.`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Delays execution for a number of milliseconds.
|
|
21
|
+
*
|
|
22
|
+
* @param ms - Delay duration in milliseconds.
|
|
23
|
+
* @returns Promise resolved after the delay.
|
|
24
|
+
*/
|
|
25
|
+
function sleep(ms) {
|
|
26
|
+
assertNonNegativeFinite(ms, "ms");
|
|
27
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Enforces a timeout for an async operation.
|
|
31
|
+
*
|
|
32
|
+
* @param operation - Promise-like operation to guard.
|
|
33
|
+
* @param ms - Timeout in milliseconds.
|
|
34
|
+
* @param message - Optional custom timeout message.
|
|
35
|
+
* @returns Promise resolved/rejected with operation result or timeout error.
|
|
36
|
+
*/
|
|
37
|
+
async function timeout(operation, ms, message) {
|
|
38
|
+
assertNonNegativeFinite(ms, "ms");
|
|
39
|
+
let timer;
|
|
40
|
+
const timeoutError = new Error(message ?? `Operation timed out after ${ms}ms.`);
|
|
41
|
+
const guard = new Promise((_, reject) => {
|
|
42
|
+
timer = setTimeout(() => reject(timeoutError), ms);
|
|
43
|
+
});
|
|
44
|
+
try {
|
|
45
|
+
return await Promise.race([Promise.resolve(operation), guard]);
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
if (timer) {
|
|
49
|
+
clearTimeout(timer);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Retries an operation with optional delay and backoff strategy.
|
|
55
|
+
*
|
|
56
|
+
* @param operation - Function that may fail and should be retried.
|
|
57
|
+
* @param options - Retry behavior configuration.
|
|
58
|
+
* @returns Successful operation result.
|
|
59
|
+
* @throws Error from final failed attempt.
|
|
60
|
+
*/
|
|
61
|
+
async function retry(operation, options = {}) {
|
|
62
|
+
const retries = options.retries ?? 3;
|
|
63
|
+
const delayMs = options.delayMs ?? 0;
|
|
64
|
+
const backoffFactor = options.backoffFactor ?? 1;
|
|
65
|
+
const shouldRetry = options.shouldRetry ?? (() => true);
|
|
66
|
+
if (!Number.isInteger(retries) || retries < 0) {
|
|
67
|
+
throw new TypeError("Expected retries to be a non-negative integer.");
|
|
68
|
+
}
|
|
69
|
+
assertNonNegativeFinite(delayMs, "delayMs");
|
|
70
|
+
if (!Number.isFinite(backoffFactor) || backoffFactor < 1) {
|
|
71
|
+
throw new TypeError("Expected backoffFactor to be a finite number greater than or equal to 1.");
|
|
72
|
+
}
|
|
73
|
+
let attempt = 0;
|
|
74
|
+
let currentDelay = delayMs;
|
|
75
|
+
while (true) {
|
|
76
|
+
try {
|
|
77
|
+
return await operation();
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
attempt += 1;
|
|
81
|
+
const canRetry = attempt <= retries && shouldRetry(error, attempt);
|
|
82
|
+
if (!canRetry) {
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
if (currentDelay > 0) {
|
|
86
|
+
await sleep(currentDelay);
|
|
87
|
+
currentDelay *= backoffFactor;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Maps values asynchronously with limited concurrency.
|
|
94
|
+
*
|
|
95
|
+
* @param values - Input collection.
|
|
96
|
+
* @param mapper - Async or sync mapper.
|
|
97
|
+
* @param options - Concurrency options.
|
|
98
|
+
* @returns Results preserving original input order.
|
|
99
|
+
*/
|
|
100
|
+
async function pMap(values, mapper, options = {}) {
|
|
101
|
+
const concurrency = options.concurrency ?? Infinity;
|
|
102
|
+
if (concurrency !== Infinity) {
|
|
103
|
+
assertPositiveInteger(concurrency, "concurrency");
|
|
104
|
+
}
|
|
105
|
+
if (values.length === 0) {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
const limit = concurrency === Infinity ? values.length : Math.min(concurrency, values.length);
|
|
109
|
+
const results = new Array(values.length);
|
|
110
|
+
let nextIndex = 0;
|
|
111
|
+
async function worker() {
|
|
112
|
+
while (true) {
|
|
113
|
+
const current = nextIndex;
|
|
114
|
+
nextIndex += 1;
|
|
115
|
+
if (current >= values.length) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
results[current] = await mapper(values[current], current);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
await Promise.all(Array.from({ length: limit }, () => worker()));
|
|
122
|
+
return results;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Debounces async calls and only resolves the latest invocation.
|
|
126
|
+
*
|
|
127
|
+
* @param fn - Async function to debounce.
|
|
128
|
+
* @param options - Debounce options.
|
|
129
|
+
* @returns Debounced async function.
|
|
130
|
+
*/
|
|
131
|
+
function debouncePromise(fn, options) {
|
|
132
|
+
const waitMs = options.waitMs;
|
|
133
|
+
assertNonNegativeFinite(waitMs, "waitMs");
|
|
134
|
+
let timer;
|
|
135
|
+
let latestCall = 0;
|
|
136
|
+
let previousReject;
|
|
137
|
+
return (...args) => new Promise((resolve, reject) => {
|
|
138
|
+
latestCall += 1;
|
|
139
|
+
const callId = latestCall;
|
|
140
|
+
if (previousReject) {
|
|
141
|
+
previousReject(new Error("Debounced by a newer call."));
|
|
142
|
+
}
|
|
143
|
+
previousReject = reject;
|
|
144
|
+
if (timer) {
|
|
145
|
+
clearTimeout(timer);
|
|
146
|
+
}
|
|
147
|
+
timer = setTimeout(async () => {
|
|
148
|
+
try {
|
|
149
|
+
const result = await fn(...args);
|
|
150
|
+
if (callId === latestCall) {
|
|
151
|
+
previousReject = undefined;
|
|
152
|
+
resolve(result);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
if (callId === latestCall) {
|
|
157
|
+
previousReject = undefined;
|
|
158
|
+
reject(error);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}, waitMs);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Throttles async calls and runs at most once per window.
|
|
166
|
+
*
|
|
167
|
+
* @param fn - Async function to throttle.
|
|
168
|
+
* @param options - Throttle options.
|
|
169
|
+
* @returns Throttled async function.
|
|
170
|
+
*/
|
|
171
|
+
function throttlePromise(fn, options) {
|
|
172
|
+
const waitMs = options.waitMs;
|
|
173
|
+
assertNonNegativeFinite(waitMs, "waitMs");
|
|
174
|
+
let lastExecution = 0;
|
|
175
|
+
let inFlight = null;
|
|
176
|
+
return async (...args) => {
|
|
177
|
+
const now = Date.now();
|
|
178
|
+
if (now - lastExecution < waitMs) {
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
lastExecution = now;
|
|
182
|
+
inFlight = Promise.resolve(fn(...args));
|
|
183
|
+
try {
|
|
184
|
+
return await inFlight;
|
|
185
|
+
}
|
|
186
|
+
finally {
|
|
187
|
+
inFlight = null;
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;AAkBA,sBAGC;AAUD,0B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AC,CAAC;AACP,CAAC;AAMD;;;;;;GAMG;AACH,SAAgB,eAAe,CAC7B,EAAkD,EAClD,OAA+B;IAE/B,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC9B,uBAAuB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAE1C,IAAI,aAAa,GAAG,CAAC,CAAC;IACtB,IAAI,QAAQ,GAA4B,IAAI,CAAC;IAE7C,OAAO,KAAK,EAAE,GAAG,IAAW,EAAE,EAAE;QAC9B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,GAAG,GAAG,aAAa,GAAG,MAAM,EAAE,CAAC;YACjC,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,aAAa,GAAG,GAAG,CAAC;QACpB,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;QACxC,IAAI,CAAC;YACH,OAAO,MAAM,QAAQ,CAAC;QACxB,CAAC;gBAAS,CAAC;YACT,QAAQ,GAAG,IAAI,CAAC;QAClB,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Delays execution for a number of milliseconds.
|
|
3
|
+
*
|
|
4
|
+
* @param ms - Delay duration in milliseconds.
|
|
5
|
+
* @returns Promise resolved after the delay.
|
|
6
|
+
*/
|
|
7
|
+
export declare function sleep(ms: number): Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* Enforces a timeout for an async operation.
|
|
10
|
+
*
|
|
11
|
+
* @param operation - Promise-like operation to guard.
|
|
12
|
+
* @param ms - Timeout in milliseconds.
|
|
13
|
+
* @param message - Optional custom timeout message.
|
|
14
|
+
* @returns Promise resolved/rejected with operation result or timeout error.
|
|
15
|
+
*/
|
|
16
|
+
export declare function timeout<T>(operation: PromiseLike<T>, ms: number, message?: string): Promise<T>;
|
|
17
|
+
export type RetryOptions = {
|
|
18
|
+
retries?: number;
|
|
19
|
+
delayMs?: number;
|
|
20
|
+
backoffFactor?: number;
|
|
21
|
+
shouldRetry?: (error: unknown, failedAttempts: number) => boolean;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Retries an operation with optional delay and backoff strategy.
|
|
25
|
+
*
|
|
26
|
+
* @param operation - Function that may fail and should be retried.
|
|
27
|
+
* @param options - Retry behavior configuration.
|
|
28
|
+
* @returns Successful operation result.
|
|
29
|
+
* @throws Error from final failed attempt.
|
|
30
|
+
*/
|
|
31
|
+
export declare function retry<T>(operation: () => Promise<T> | T, options?: RetryOptions): Promise<T>;
|
|
32
|
+
export type PMapOptions = {
|
|
33
|
+
concurrency?: number;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Maps values asynchronously with limited concurrency.
|
|
37
|
+
*
|
|
38
|
+
* @param values - Input collection.
|
|
39
|
+
* @param mapper - Async or sync mapper.
|
|
40
|
+
* @param options - Concurrency options.
|
|
41
|
+
* @returns Results preserving original input order.
|
|
42
|
+
*/
|
|
43
|
+
export declare function pMap<T, R>(values: readonly T[], mapper: (value: T, index: number) => Promise<R> | R, options?: PMapOptions): Promise<R[]>;
|
|
44
|
+
export type DebouncePromiseOptions = {
|
|
45
|
+
waitMs: number;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Debounces async calls and only resolves the latest invocation.
|
|
49
|
+
*
|
|
50
|
+
* @param fn - Async function to debounce.
|
|
51
|
+
* @param options - Debounce options.
|
|
52
|
+
* @returns Debounced async function.
|
|
53
|
+
*/
|
|
54
|
+
export declare function debouncePromise<TArgs extends unknown[], TResult>(fn: (...args: TArgs) => Promise<TResult> | TResult, options: DebouncePromiseOptions): (...args: TArgs) => Promise<TResult>;
|
|
55
|
+
export type ThrottlePromiseOptions = {
|
|
56
|
+
waitMs: number;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Throttles async calls and runs at most once per window.
|
|
60
|
+
*
|
|
61
|
+
* @param fn - Async function to throttle.
|
|
62
|
+
* @param options - Throttle options.
|
|
63
|
+
* @returns Throttled async function.
|
|
64
|
+
*/
|
|
65
|
+
export declare function throttlePromise<TArgs extends unknown[], TResult>(fn: (...args: TArgs) => Promise<TResult> | TResult, options: ThrottlePromiseOptions): (...args: TArgs) => Promise<TResult | undefined>;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
function assertNonNegativeFinite(value, label) {
|
|
2
|
+
if (!Number.isFinite(value) || value < 0) {
|
|
3
|
+
throw new TypeError(`Expected ${label} to be a non-negative finite number.`);
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
function assertPositiveInteger(value, label) {
|
|
7
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
8
|
+
throw new TypeError(`Expected ${label} to be a positive integer.`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Delays execution for a number of milliseconds.
|
|
13
|
+
*
|
|
14
|
+
* @param ms - Delay duration in milliseconds.
|
|
15
|
+
* @returns Promise resolved after the delay.
|
|
16
|
+
*/
|
|
17
|
+
export function sleep(ms) {
|
|
18
|
+
assertNonNegativeFinite(ms, "ms");
|
|
19
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Enforces a timeout for an async operation.
|
|
23
|
+
*
|
|
24
|
+
* @param operation - Promise-like operation to guard.
|
|
25
|
+
* @param ms - Timeout in milliseconds.
|
|
26
|
+
* @param message - Optional custom timeout message.
|
|
27
|
+
* @returns Promise resolved/rejected with operation result or timeout error.
|
|
28
|
+
*/
|
|
29
|
+
export async function timeout(operation, ms, message) {
|
|
30
|
+
assertNonNegativeFinite(ms, "ms");
|
|
31
|
+
let timer;
|
|
32
|
+
const timeoutError = new Error(message ?? `Operation timed out after ${ms}ms.`);
|
|
33
|
+
const guard = new Promise((_, reject) => {
|
|
34
|
+
timer = setTimeout(() => reject(timeoutError), ms);
|
|
35
|
+
});
|
|
36
|
+
try {
|
|
37
|
+
return await Promise.race([Promise.resolve(operation), guard]);
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
if (timer) {
|
|
41
|
+
clearTimeout(timer);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Retries an operation with optional delay and backoff strategy.
|
|
47
|
+
*
|
|
48
|
+
* @param operation - Function that may fail and should be retried.
|
|
49
|
+
* @param options - Retry behavior configuration.
|
|
50
|
+
* @returns Successful operation result.
|
|
51
|
+
* @throws Error from final failed attempt.
|
|
52
|
+
*/
|
|
53
|
+
export async function retry(operation, options = {}) {
|
|
54
|
+
const retries = options.retries ?? 3;
|
|
55
|
+
const delayMs = options.delayMs ?? 0;
|
|
56
|
+
const backoffFactor = options.backoffFactor ?? 1;
|
|
57
|
+
const shouldRetry = options.shouldRetry ?? (() => true);
|
|
58
|
+
if (!Number.isInteger(retries) || retries < 0) {
|
|
59
|
+
throw new TypeError("Expected retries to be a non-negative integer.");
|
|
60
|
+
}
|
|
61
|
+
assertNonNegativeFinite(delayMs, "delayMs");
|
|
62
|
+
if (!Number.isFinite(backoffFactor) || backoffFactor < 1) {
|
|
63
|
+
throw new TypeError("Expected backoffFactor to be a finite number greater than or equal to 1.");
|
|
64
|
+
}
|
|
65
|
+
let attempt = 0;
|
|
66
|
+
let currentDelay = delayMs;
|
|
67
|
+
while (true) {
|
|
68
|
+
try {
|
|
69
|
+
return await operation();
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
attempt += 1;
|
|
73
|
+
const canRetry = attempt <= retries && shouldRetry(error, attempt);
|
|
74
|
+
if (!canRetry) {
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
if (currentDelay > 0) {
|
|
78
|
+
await sleep(currentDelay);
|
|
79
|
+
currentDelay *= backoffFactor;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Maps values asynchronously with limited concurrency.
|
|
86
|
+
*
|
|
87
|
+
* @param values - Input collection.
|
|
88
|
+
* @param mapper - Async or sync mapper.
|
|
89
|
+
* @param options - Concurrency options.
|
|
90
|
+
* @returns Results preserving original input order.
|
|
91
|
+
*/
|
|
92
|
+
export async function pMap(values, mapper, options = {}) {
|
|
93
|
+
const concurrency = options.concurrency ?? Infinity;
|
|
94
|
+
if (concurrency !== Infinity) {
|
|
95
|
+
assertPositiveInteger(concurrency, "concurrency");
|
|
96
|
+
}
|
|
97
|
+
if (values.length === 0) {
|
|
98
|
+
return [];
|
|
99
|
+
}
|
|
100
|
+
const limit = concurrency === Infinity ? values.length : Math.min(concurrency, values.length);
|
|
101
|
+
const results = new Array(values.length);
|
|
102
|
+
let nextIndex = 0;
|
|
103
|
+
async function worker() {
|
|
104
|
+
while (true) {
|
|
105
|
+
const current = nextIndex;
|
|
106
|
+
nextIndex += 1;
|
|
107
|
+
if (current >= values.length) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
results[current] = await mapper(values[current], current);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
await Promise.all(Array.from({ length: limit }, () => worker()));
|
|
114
|
+
return results;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Debounces async calls and only resolves the latest invocation.
|
|
118
|
+
*
|
|
119
|
+
* @param fn - Async function to debounce.
|
|
120
|
+
* @param options - Debounce options.
|
|
121
|
+
* @returns Debounced async function.
|
|
122
|
+
*/
|
|
123
|
+
export function debouncePromise(fn, options) {
|
|
124
|
+
const waitMs = options.waitMs;
|
|
125
|
+
assertNonNegativeFinite(waitMs, "waitMs");
|
|
126
|
+
let timer;
|
|
127
|
+
let latestCall = 0;
|
|
128
|
+
let previousReject;
|
|
129
|
+
return (...args) => new Promise((resolve, reject) => {
|
|
130
|
+
latestCall += 1;
|
|
131
|
+
const callId = latestCall;
|
|
132
|
+
if (previousReject) {
|
|
133
|
+
previousReject(new Error("Debounced by a newer call."));
|
|
134
|
+
}
|
|
135
|
+
previousReject = reject;
|
|
136
|
+
if (timer) {
|
|
137
|
+
clearTimeout(timer);
|
|
138
|
+
}
|
|
139
|
+
timer = setTimeout(async () => {
|
|
140
|
+
try {
|
|
141
|
+
const result = await fn(...args);
|
|
142
|
+
if (callId === latestCall) {
|
|
143
|
+
previousReject = undefined;
|
|
144
|
+
resolve(result);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
if (callId === latestCall) {
|
|
149
|
+
previousReject = undefined;
|
|
150
|
+
reject(error);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}, waitMs);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Throttles async calls and runs at most once per window.
|
|
158
|
+
*
|
|
159
|
+
* @param fn - Async function to throttle.
|
|
160
|
+
* @param options - Throttle options.
|
|
161
|
+
* @returns Throttled async function.
|
|
162
|
+
*/
|
|
163
|
+
export function throttlePromise(fn, options) {
|
|
164
|
+
const waitMs = options.waitMs;
|
|
165
|
+
assertNonNegativeFinite(waitMs, "waitMs");
|
|
166
|
+
let lastExecution = 0;
|
|
167
|
+
let inFlight = null;
|
|
168
|
+
return async (...args) => {
|
|
169
|
+
const now = Date.now();
|
|
170
|
+
if (now - lastExecution < waitMs) {
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
lastExecution = now;
|
|
174
|
+
inFlight = Promise.resolve(fn(...args));
|
|
175
|
+
try {
|
|
176
|
+
return await inFlight;
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
inFlight = null;
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,SAAS,uBAA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;AACH,MAAM,UAAU,eAAe,CAC7B,EAAkD,EAClD,OAA+B;IAE/B,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC9B,uBAAuB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAE1C,IAAI,aAAa,GAAG,CAAC,CAAC;IACtB,IAAI,QAAQ,GAA4B,IAAI,CAAC;IAE7C,OAAO,KAAK,EAAE,GAAG,IAAW,EAAE,EAAE;QAC9B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,GAAG,GAAG,aAAa,GAAG,MAAM,EAAE,CAAC;YACjC,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,aAAa,GAAG,GAAG,CAAC;QACpB,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;QACxC,IAAI,CAAC;YACH,OAAO,MAAM,QAAQ,CAAC;QACxB,CAAC;gBAAS,CAAC;YACT,QAAQ,GAAG,IAAI,CAAC;QAClB,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jdsalasc/solvejs-async",
|
|
3
|
+
"version": "1.5.0",
|
|
4
|
+
"description": "Zero-dependency JavaScript/TypeScript async utilities for production: sleep, promise timeout, retry with backoff, and concurrency-limited pMap.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"main": "./dist/cjs/index.cjs",
|
|
9
|
+
"module": "./dist/esm/index.js",
|
|
10
|
+
"types": "./dist/esm/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/esm/index.d.ts",
|
|
14
|
+
"import": "./dist/esm/index.js",
|
|
15
|
+
"require": "./dist/cjs/index.cjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "npm run clean && npm run build:esm && npm run build:cjs",
|
|
24
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
25
|
+
"build:cjs": "tsc -p tsconfig.cjs.json && node ./scripts/rename-cjs.mjs",
|
|
26
|
+
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
27
|
+
"test": "npm run build && node --test test/*.test.mjs",
|
|
28
|
+
"lint": "node -e \"console.log('No lint configured for @jdsalasc/solvejs-async')\""
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"author": "jdsalasc",
|
|
34
|
+
"homepage": "https://github.com/jdsalasca/solvejs#readme",
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/jdsalasca/solvejs.git"
|
|
38
|
+
},
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/jdsalasca/solvejs/issues"
|
|
41
|
+
},
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=18"
|
|
44
|
+
},
|
|
45
|
+
"keywords": [
|
|
46
|
+
"javascript async utilities",
|
|
47
|
+
"typescript async utilities",
|
|
48
|
+
"promise timeout",
|
|
49
|
+
"retry with backoff",
|
|
50
|
+
"concurrency limit",
|
|
51
|
+
"pmap",
|
|
52
|
+
"sleep function",
|
|
53
|
+
"zero dependency",
|
|
54
|
+
"solvejs"
|
|
55
|
+
]
|
|
56
|
+
}
|