@common.js/p-timeout 6.1.1 → 6.1.3
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 +1 -1
- package/index.d.ts +2 -2
- package/index.js +19 -15
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
|
|
3
3
|
The [p-timeout](https://www.npmjs.com/package/p-timeout) package exported as CommonJS modules.
|
|
4
4
|
|
|
5
|
-
Exported from [p-timeout@6.1.
|
|
5
|
+
Exported from [p-timeout@6.1.3](https://www.npmjs.com/package/p-timeout/v/6.1.3) using https://github.com/etienne-martin/common.js.
|
package/index.d.ts
CHANGED
|
@@ -3,12 +3,12 @@ export class TimeoutError extends Error {
|
|
|
3
3
|
constructor(message?: string);
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
export
|
|
6
|
+
export type ClearablePromise<T> = {
|
|
7
7
|
/**
|
|
8
8
|
Clear the timeout.
|
|
9
9
|
*/
|
|
10
10
|
clear: () => void;
|
|
11
|
-
}
|
|
11
|
+
} & Promise<T>;
|
|
12
12
|
|
|
13
13
|
export type Options<ReturnType> = {
|
|
14
14
|
/**
|
package/index.js
CHANGED
|
@@ -322,23 +322,29 @@ function pTimeout(promise, options) {
|
|
|
322
322
|
clearTimeout: clearTimeout
|
|
323
323
|
} : _customTimers;
|
|
324
324
|
var timer;
|
|
325
|
-
var
|
|
325
|
+
var wrappedPromise = new Promise(function(resolve, reject) {
|
|
326
326
|
if (typeof milliseconds !== "number" || Math.sign(milliseconds) !== 1) {
|
|
327
327
|
throw new TypeError("Expected `milliseconds` to be a positive number, got `".concat(milliseconds, "`"));
|
|
328
328
|
}
|
|
329
|
-
if (milliseconds === Number.POSITIVE_INFINITY) {
|
|
330
|
-
resolve(promise);
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
329
|
if (options.signal) {
|
|
334
330
|
var signal = options.signal;
|
|
335
331
|
if (signal.aborted) {
|
|
336
332
|
reject(getAbortedReason(signal));
|
|
337
333
|
}
|
|
338
|
-
|
|
334
|
+
var abortHandler = function() {
|
|
339
335
|
reject(getAbortedReason(signal));
|
|
336
|
+
};
|
|
337
|
+
signal.addEventListener("abort", abortHandler, {
|
|
338
|
+
once: true
|
|
339
|
+
});
|
|
340
|
+
promise.finally(function() {
|
|
341
|
+
signal.removeEventListener("abort", abortHandler);
|
|
340
342
|
});
|
|
341
343
|
}
|
|
344
|
+
if (milliseconds === Number.POSITIVE_INFINITY) {
|
|
345
|
+
promise.then(resolve, reject);
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
342
348
|
// We create the error outside of `setTimeout` to preserve the stack trace.
|
|
343
349
|
var timeoutError = new TimeoutError();
|
|
344
350
|
timer = customTimers.setTimeout.call(undefined, function() {
|
|
@@ -370,8 +376,8 @@ function pTimeout(promise, options) {
|
|
|
370
376
|
_state.trys.push([
|
|
371
377
|
0,
|
|
372
378
|
2,
|
|
373
|
-
|
|
374
|
-
|
|
379
|
+
,
|
|
380
|
+
3
|
|
375
381
|
]);
|
|
376
382
|
return [
|
|
377
383
|
4,
|
|
@@ -383,21 +389,16 @@ function pTimeout(promise, options) {
|
|
|
383
389
|
]);
|
|
384
390
|
return [
|
|
385
391
|
3,
|
|
386
|
-
|
|
392
|
+
3
|
|
387
393
|
];
|
|
388
394
|
case 2:
|
|
389
395
|
error = _state.sent();
|
|
390
396
|
reject(error);
|
|
391
397
|
return [
|
|
392
398
|
3,
|
|
393
|
-
|
|
399
|
+
3
|
|
394
400
|
];
|
|
395
401
|
case 3:
|
|
396
|
-
customTimers.clearTimeout.call(undefined, timer);
|
|
397
|
-
return [
|
|
398
|
-
7
|
|
399
|
-
];
|
|
400
|
-
case 4:
|
|
401
402
|
return [
|
|
402
403
|
2
|
|
403
404
|
];
|
|
@@ -405,6 +406,9 @@ function pTimeout(promise, options) {
|
|
|
405
406
|
});
|
|
406
407
|
})();
|
|
407
408
|
});
|
|
409
|
+
var cancelablePromise = wrappedPromise.finally(function() {
|
|
410
|
+
cancelablePromise.clear();
|
|
411
|
+
});
|
|
408
412
|
cancelablePromise.clear = function() {
|
|
409
413
|
customTimers.clearTimeout.call(undefined, timer);
|
|
410
414
|
timer = undefined;
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@common.js/p-timeout",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.3",
|
|
4
4
|
"description": "p-timeout package exported as CommonJS modules",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "etienne-martin/common.js",
|
|
7
7
|
"funding": "https://github.com/sponsors/sindresorhus",
|
|
8
8
|
"type": "commonjs",
|
|
9
9
|
"types": "./index.d.ts",
|
|
10
|
+
"sideEffects": false,
|
|
10
11
|
"engines": {
|
|
11
12
|
"node": ">=14.16"
|
|
12
13
|
},
|
|
@@ -22,9 +23,10 @@
|
|
|
22
23
|
"delay": "^5.0.0",
|
|
23
24
|
"in-range": "^3.0.0",
|
|
24
25
|
"p-cancelable": "^4.0.1",
|
|
26
|
+
"sinon": "^19.0.2",
|
|
25
27
|
"time-span": "^5.1.0",
|
|
26
28
|
"tsd": "^0.22.0",
|
|
27
|
-
"xo": "^0.
|
|
29
|
+
"xo": "^0.54.2"
|
|
28
30
|
},
|
|
29
31
|
"homepage": "https://github.com/etienne-martin/common.js#readme",
|
|
30
32
|
"dependencies": {},
|