Detects when a promise is idle (does not create asynchronous events) for longer than permitted amount of time.
OTHER License
Detects when a promise is idle (does not create asynchronous events) for longer than permitted amount of time.
import {
timeoutIdlePromise,
TimeoutError,
} from 'timeout-idle-promise';
/**
* @param {Function} promiseFactory
* @param {number} maximumIdleTime Idle timeout in milliseconds.
* @throws TimeoutError
*/
timeoutIdlePromise(promiseFactory);
// Rejected with Idle promise timeout.
timeoutIdlePromise(() => {
return new Promise((resolve) => {
});
}, 1000);
// Resolved.
timeoutIdlePromise(() => {
return new Promise((resolve) => {
setTimeout(() => {
setTimeout(() => {
setTimeout(() => {
resolve();
}, 500);
}, 500);
}, 500);
});
}, 1000);