Add types, tests, docs
This commit is contained in:
parent
557dbb019a
commit
4bf9e3b678
|
@ -47,7 +47,7 @@ export type Options<ReturnType> = {
|
|||
|
||||
If you do a custom error, it's recommended to sub-class `pTimeout.TimeoutError`.
|
||||
*/
|
||||
message?: string | Error;
|
||||
message?: string | Error | false;
|
||||
|
||||
/**
|
||||
Custom implementations for the `setTimeout` and `clearTimeout` functions.
|
||||
|
|
2
index.js
2
index.js
|
@ -80,7 +80,7 @@ export default function pTimeout(promise, options) {
|
|||
if (typeof promise.cancel === 'function') {
|
||||
promise.cancel();
|
||||
}
|
||||
|
||||
|
||||
if (message === false) {
|
||||
resolve();
|
||||
}
|
||||
|
|
|
@ -50,10 +50,10 @@ Passing `Infinity` will cause it to never time out.
|
|||
|
||||
##### message
|
||||
|
||||
Type: `string | Error`\
|
||||
Type: `string | Error | false`\
|
||||
Default: `'Promise timed out after 50 milliseconds'`
|
||||
|
||||
Specify a custom error message or error.
|
||||
Specify a custom error message or error. If you supply `false`, the promise will resolve successfully instead of rejecting.
|
||||
|
||||
If you do a custom error, it's recommended to sub-class `pTimeout.TimeoutError`.
|
||||
|
||||
|
|
7
test.js
7
test.js
|
@ -35,6 +35,13 @@ test('rejects after timeout', async t => {
|
|||
await t.throwsAsync(pTimeout(delay(200), {milliseconds: 50}), {instanceOf: TimeoutError});
|
||||
});
|
||||
|
||||
test('resolves after timeout with message:false', async t => {
|
||||
t.is(
|
||||
await pTimeout(delay(200), {milliseconds: 50, message: false}),
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
|
||||
test('rejects before timeout if specified promise rejects', async t => {
|
||||
await t.throwsAsync(pTimeout(delay(50).then(() => {
|
||||
throw fixtureError;
|
||||
|
|
Loading…
Reference in New Issue