update README and index.d.ts for docs

This commit is contained in:
İlker Yıldırım 2020-09-01 23:27:31 +03:00
parent dcc85e45a1
commit 834cc6354c
3 changed files with 8 additions and 7 deletions

7
index.d.ts vendored
View File

@ -50,7 +50,7 @@ declare const pTimeout: {
default: typeof pTimeout;
/**
Timeout a promise after a specified amount of time.
Timeout a promise after a specified amount of time. It returns a decorated promise having `.clear()` method to be able to clear timeout.
If you pass in a cancelable promise, specifically a promise with a `.cancel()` method, that method will be called when the `pTimeout` promise times out.
@ -78,7 +78,7 @@ declare const pTimeout: {
): ClearablePromise<ValueType>;
/**
Timeout a promise after a specified amount of time.
Timeout a promise after a specified amount of time. It returns a decorated promise having `.clear()` method to be able to clear timeout.
If you pass in a cancelable promise, specifically a promise with a `.cancel()` method, that method will be called when the `pTimeout` promise times out.
@ -97,6 +97,7 @@ declare const pTimeout: {
pTimeout(delayedPromise(), 50, () => {
return pTimeout(delayedPromise(), 300);
});
promise.clear(); //Clear timeout
```
*/
<ValueType, ReturnType>(
@ -105,6 +106,6 @@ declare const pTimeout: {
fallback: () => ReturnType | Promise<ReturnType>,
options?: pTimeout.Options
): ClearablePromise<ValueType | ReturnType>;
};
};
export = pTimeout;

View File

@ -9,7 +9,7 @@ class TimeoutError extends Error {
const pTimeout = (promise, milliseconds, fallback, options) => {
let timer;
const cancelablePromise = new Promise((resolve, reject) => {
const clearablePromise = new Promise((resolve, reject) => {
if (typeof milliseconds !== 'number' || milliseconds < 0) {
throw new TypeError('Expected `milliseconds` to be a positive number');
}
@ -56,12 +56,12 @@ const pTimeout = (promise, milliseconds, fallback, options) => {
})();
});
cancelablePromise.clear = () => {
clearablePromise.clear = () => {
clearTimeout(timer);
timer = undefined;
};
return cancelablePromise;
return clearablePromise;
};
module.exports = pTimeout;

View File

@ -25,7 +25,7 @@ pTimeout(delayedPromise, 50).then(() => 'foo');
### pTimeout(input, milliseconds, message?, options?)
### pTimeout(input, milliseconds, fallback?, options?)
Returns a decorated `input` that times out after `milliseconds` time.
Returns a decorated `input` that times out after `milliseconds` time. Decorated input has `.clear()` method to be able to clear timeout.
If you pass in a cancelable promise, specifically a promise with a `.cancel()` method, that method will be called when the `pTimeout` promise times out.