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.
|
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;
|
name;
|
||||||
constructor(message) {
|
constructor(message) {
|
||||||
super(message);
|
super(message);
|
||||||
this.name = "TimeoutError";
|
this.name = "TimeoutError";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
exports.TimeoutError = TimeoutError;
|
||||||
/**
|
/**
|
||||||
An error to be thrown when the request is aborted by AbortController.
|
An error to be thrown when the request is aborted by AbortController.
|
||||||
DOMException is thrown instead of this Error when DOMException is available.
|
DOMException is thrown instead of this Error when DOMException is available.
|
||||||
*/
|
*/
|
||||||
export class AbortError extends Error {
|
class AbortError extends Error {
|
||||||
name;
|
name;
|
||||||
constructor(message) {
|
constructor(message) {
|
||||||
super();
|
super();
|
||||||
|
@ -40,6 +44,7 @@ export class AbortError extends Error {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
exports.AbortError = AbortError;
|
||||||
/**
|
/**
|
||||||
TODO: Remove AbortError and just throw DOMException when targeting Node 18.
|
TODO: Remove AbortError and just throw DOMException when targeting Node 18.
|
||||||
*/
|
*/
|
||||||
|
@ -55,7 +60,7 @@ const getAbortedReason = (signal) => {
|
||||||
: signal.reason;
|
: signal.reason;
|
||||||
return reason instanceof Error ? reason : getDOMException(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;
|
const { milliseconds, fallback, message, customTimers = { setTimeout, clearTimeout }, } = options;
|
||||||
let timer;
|
let timer;
|
||||||
const cancelablePromise = new Promise((resolve, reject) => {
|
const cancelablePromise = new Promise((resolve, reject) => {
|
||||||
|
@ -113,3 +118,4 @@ export default function pTimeout(promise, options) {
|
||||||
};
|
};
|
||||||
return cancelablePromise;
|
return cancelablePromise;
|
||||||
}
|
}
|
||||||
|
exports.default = pTimeout;
|
||||||
|
|
93
package.json
93
package.json
|
@ -1,49 +1,48 @@
|
||||||
{
|
{
|
||||||
"name": "p-timeout",
|
"name": "p-timeout",
|
||||||
"version": "6.0.0",
|
"version": "6.0.0",
|
||||||
"description": "Timeout a promise after a specified amount of time",
|
"main": "dist/index.js",
|
||||||
"license": "MIT",
|
"description": "Timeout a promise after a specified amount of time",
|
||||||
"repository": "sindresorhus/p-timeout",
|
"license": "MIT",
|
||||||
"funding": "https://github.com/sponsors/sindresorhus",
|
"repository": "sindresorhus/p-timeout",
|
||||||
"author": {
|
"funding": "https://github.com/sponsors/sindresorhus",
|
||||||
"name": "Sindre Sorhus",
|
"author": {
|
||||||
"email": "sindresorhus@gmail.com",
|
"name": "Sindre Sorhus",
|
||||||
"url": "https://sindresorhus.com"
|
"email": "sindresorhus@gmail.com",
|
||||||
},
|
"url": "https://sindresorhus.com"
|
||||||
"type": "module",
|
},
|
||||||
"exports": "./index.js",
|
"type": "commonjs",
|
||||||
"types": "./index.d.ts",
|
"engines": {
|
||||||
"engines": {
|
"node": ">=14.16"
|
||||||
"node": ">=14.16"
|
},
|
||||||
},
|
"scripts": {
|
||||||
"scripts": {
|
"test": "xo && ava && tsd"
|
||||||
"test": "xo && ava && tsd"
|
},
|
||||||
},
|
"files": [
|
||||||
"files": [
|
"src/index.js",
|
||||||
"src/index.js",
|
"index.d.ts"
|
||||||
"index.d.ts"
|
],
|
||||||
],
|
"keywords": [
|
||||||
"keywords": [
|
"promise",
|
||||||
"promise",
|
"timeout",
|
||||||
"timeout",
|
"error",
|
||||||
"error",
|
"invalidate",
|
||||||
"invalidate",
|
"async",
|
||||||
"async",
|
"await",
|
||||||
"await",
|
"promises",
|
||||||
"promises",
|
"time",
|
||||||
"time",
|
"out",
|
||||||
"out",
|
"cancel",
|
||||||
"cancel",
|
"bluebird"
|
||||||
"bluebird"
|
],
|
||||||
],
|
"devDependencies": {
|
||||||
"devDependencies": {
|
"ava": "^4.3.1",
|
||||||
"ava": "^4.3.1",
|
"delay": "^5.0.0",
|
||||||
"delay": "^5.0.0",
|
"in-range": "^3.0.0",
|
||||||
"in-range": "^3.0.0",
|
"p-cancelable": "^4.0.1",
|
||||||
"p-cancelable": "^4.0.1",
|
"prettier": "^2.8.1",
|
||||||
"prettier": "^2.8.1",
|
"time-span": "^5.1.0",
|
||||||
"time-span": "^5.1.0",
|
"tsd": "^0.22.0",
|
||||||
"tsd": "^0.22.0",
|
"xo": "^0.51.0"
|
||||||
"xo": "^0.51.0"
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"module": "esnext",
|
"module": "commonjs",
|
||||||
"target": "esnext",
|
"target": "esnext",
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"sourceMap": false,
|
"sourceMap": false,
|
||||||
|
|
Loading…
Reference in New Issue