https://github.com/gajus/timeout-idle-promise
Detects when a promise is idle (does not create asynchronous events) for longer than permitted amount of time.
https://github.com/gajus/timeout-idle-promise
promise
Last synced: 1 day ago
JSON representation
Detects when a promise is idle (does not create asynchronous events) for longer than permitted amount of time.
- Host: GitHub
- URL: https://github.com/gajus/timeout-idle-promise
- Owner: gajus
- License: other
- Created: 2019-11-01T15:13:17.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-01T15:22:29.000Z (over 5 years ago)
- Last Synced: 2025-06-18T01:42:04.984Z (14 days ago)
- Topics: promise
- Language: JavaScript
- Size: 4.88 KB
- Stars: 10
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# timeout-idle-promise
[](https://travis-ci.org/gajus/timeout-idle-promise)
[](https://coveralls.io/github/gajus/timeout-idle-promise)
[](https://www.npmjs.org/package/timeout-idle-promise)
[](https://github.com/gajus/canonical)
[](https://twitter.com/kuizinas)Detects when a promise is idle (does not create asynchronous events) for longer than permitted amount of time.
## API
```js
import {
timeoutIdlePromise,
TimeoutError,
} from 'timeout-idle-promise';/**
* @param {Function} promiseFactory
* @param {number} maximumIdleTime Idle timeout in milliseconds.
* @throws TimeoutError
*/
timeoutIdlePromise(promiseFactory);```
## Example Usage
```js
// 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);```