Require Node.js 10
This commit is contained in:
parent
085f437e49
commit
3249b2f014
|
@ -13,7 +13,6 @@ jobs:
|
||||||
- 14
|
- 14
|
||||||
- 12
|
- 12
|
||||||
- 10
|
- 10
|
||||||
- 8
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-node@v1
|
- uses: actions/setup-node@v1
|
||||||
|
|
|
@ -37,10 +37,14 @@ declare namespace pTimeout {
|
||||||
setTimeout: typeof global.setTimeout;
|
setTimeout: typeof global.setTimeout;
|
||||||
clearTimeout: typeof global.clearTimeout;
|
clearTimeout: typeof global.clearTimeout;
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
declare const pTimeout: {
|
declare const pTimeout: {
|
||||||
|
TimeoutError: typeof TimeoutErrorClass;
|
||||||
|
|
||||||
|
default: typeof pTimeout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Timeout a promise after a specified amount of time.
|
Timeout a promise after a specified amount of time.
|
||||||
|
|
||||||
|
@ -97,11 +101,6 @@ declare const pTimeout: {
|
||||||
fallback: () => ReturnType | Promise<ReturnType>,
|
fallback: () => ReturnType | Promise<ReturnType>,
|
||||||
options?: pTimeout.Options
|
options?: pTimeout.Options
|
||||||
): Promise<ValueType | ReturnType>;
|
): Promise<ValueType | ReturnType>;
|
||||||
|
|
||||||
TimeoutError: typeof TimeoutErrorClass;
|
|
||||||
|
|
||||||
// TODO: Remove this for the next major release
|
|
||||||
default: typeof pTimeout;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export = pTimeout;
|
export = pTimeout;
|
||||||
|
|
15
index.js
15
index.js
|
@ -1,7 +1,5 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const pFinally = require('p-finally');
|
|
||||||
|
|
||||||
class TimeoutError extends Error {
|
class TimeoutError extends Error {
|
||||||
constructor(message) {
|
constructor(message) {
|
||||||
super(message);
|
super(message);
|
||||||
|
@ -45,14 +43,15 @@ const pTimeout = (promise, milliseconds, fallback, options) => new Promise((reso
|
||||||
reject(timeoutError);
|
reject(timeoutError);
|
||||||
}, milliseconds);
|
}, milliseconds);
|
||||||
|
|
||||||
// TODO: Use native `finally` keyword when targeting Node.js 10
|
(async () => {
|
||||||
pFinally(
|
try {
|
||||||
// eslint-disable-next-line promise/prefer-await-to-then
|
resolve(await promise);
|
||||||
promise.then(resolve, reject),
|
} catch (error) {
|
||||||
() => {
|
reject(error);
|
||||||
|
} finally {
|
||||||
options.customTimers.clearTimeout(timer);
|
options.customTimers.clearTimeout(timer);
|
||||||
}
|
}
|
||||||
);
|
})();
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = pTimeout;
|
module.exports = pTimeout;
|
||||||
|
|
|
@ -2,8 +2,13 @@ import {expectType, expectError} from 'tsd';
|
||||||
import pTimeout = require('.');
|
import pTimeout = require('.');
|
||||||
import {TimeoutError} from '.';
|
import {TimeoutError} from '.';
|
||||||
|
|
||||||
const delayedPromise: () => Promise<string> = () =>
|
const delayedPromise: () => Promise<string> = async () => {
|
||||||
new Promise(resolve => setTimeout(() => resolve('foo'), 200));
|
return new Promise(resolve => {
|
||||||
|
setTimeout(() => {
|
||||||
|
resolve('foo');
|
||||||
|
}, 200);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
pTimeout(delayedPromise(), 50).then(() => 'foo');
|
pTimeout(delayedPromise(), 50).then(() => 'foo');
|
||||||
pTimeout(delayedPromise(), 50, () => {
|
pTimeout(delayedPromise(), 50, () => {
|
||||||
|
|
11
package.json
11
package.json
|
@ -10,7 +10,7 @@
|
||||||
"url": "https://sindresorhus.com"
|
"url": "https://sindresorhus.com"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8"
|
"node": ">=10"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "xo && ava && tsd"
|
"test": "xo && ava && tsd"
|
||||||
|
@ -32,14 +32,11 @@
|
||||||
"cancel",
|
"cancel",
|
||||||
"bluebird"
|
"bluebird"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
|
||||||
"p-finally": "^1.0.0"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"ava": "^1.4.1",
|
"ava": "^2.4.0",
|
||||||
"delay": "^4.1.0",
|
"delay": "^4.4.0",
|
||||||
"p-cancelable": "^2.0.0",
|
"p-cancelable": "^2.0.0",
|
||||||
"tsd": "^0.13.1",
|
"tsd": "^0.13.1",
|
||||||
"xo": "^0.24.0"
|
"xo": "^0.35.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue