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`.
|
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.
|
Custom implementations for the `setTimeout` and `clearTimeout` functions.
|
||||||
|
|
|
@ -50,10 +50,10 @@ Passing `Infinity` will cause it to never time out.
|
||||||
|
|
||||||
##### message
|
##### message
|
||||||
|
|
||||||
Type: `string | Error`\
|
Type: `string | Error | false`\
|
||||||
Default: `'Promise timed out after 50 milliseconds'`
|
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`.
|
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});
|
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 => {
|
test('rejects before timeout if specified promise rejects', async t => {
|
||||||
await t.throwsAsync(pTimeout(delay(50).then(() => {
|
await t.throwsAsync(pTimeout(delay(50).then(() => {
|
||||||
throw fixtureError;
|
throw fixtureError;
|
||||||
|
|
Loading…
Reference in New Issue