Compare commits
2 Commits
a3434a77f7
...
4d4bee14a2
Author | SHA1 | Date |
---|---|---|
Derrick Hammer | 4d4bee14a2 | |
Derrick Hammer | cc29396abb |
|
@ -1,3 +1,6 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AbortError = exports.TimeoutError = void 0;
|
||||
/**
|
||||
Timeout a promise after a specified amount of time.
|
||||
|
||||
|
@ -21,18 +24,19 @@ await pTimeout(delayedPromise(), {
|
|||
});
|
||||
```
|
||||
*/
|
||||
export class TimeoutError extends Error {
|
||||
class TimeoutError extends Error {
|
||||
name;
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "TimeoutError";
|
||||
}
|
||||
}
|
||||
exports.TimeoutError = TimeoutError;
|
||||
/**
|
||||
An error to be thrown when the request is aborted by AbortController.
|
||||
DOMException is thrown instead of this Error when DOMException is available.
|
||||
*/
|
||||
export class AbortError extends Error {
|
||||
class AbortError extends Error {
|
||||
name;
|
||||
constructor(message) {
|
||||
super();
|
||||
|
@ -40,6 +44,7 @@ export class AbortError extends Error {
|
|||
this.message = message;
|
||||
}
|
||||
}
|
||||
exports.AbortError = AbortError;
|
||||
/**
|
||||
TODO: Remove AbortError and just throw DOMException when targeting Node 18.
|
||||
*/
|
||||
|
@ -55,7 +60,7 @@ const getAbortedReason = (signal) => {
|
|||
: signal.reason;
|
||||
return reason instanceof Error ? reason : getDOMException(reason);
|
||||
};
|
||||
export default function pTimeout(promise, options) {
|
||||
function pTimeout(promise, options) {
|
||||
const { milliseconds, fallback, message, customTimers = { setTimeout, clearTimeout }, } = options;
|
||||
let timer;
|
||||
const cancelablePromise = new Promise((resolve, reject) => {
|
||||
|
@ -113,3 +118,4 @@ export default function pTimeout(promise, options) {
|
|||
};
|
||||
return cancelablePromise;
|
||||
}
|
||||
exports.default = pTimeout;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"name": "p-timeout",
|
||||
"version": "6.0.0",
|
||||
"main": "dist/index.js",
|
||||
"description": "Timeout a promise after a specified amount of time",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/p-timeout",
|
||||
|
@ -10,9 +11,7 @@
|
|||
"email": "sindresorhus@gmail.com",
|
||||
"url": "https://sindresorhus.com"
|
||||
},
|
||||
"type": "module",
|
||||
"exports": "./index.js",
|
||||
"types": "./index.d.ts",
|
||||
"type": "commonjs",
|
||||
"engines": {
|
||||
"node": ">=14.16"
|
||||
},
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"strict": true,
|
||||
"module": "esnext",
|
||||
"module": "commonjs",
|
||||
"target": "esnext",
|
||||
"esModuleInterop": true,
|
||||
"sourceMap": false,
|
||||
|
|
Loading…
Reference in New Issue