Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pocesar/js-delayable-idle-abort-promise
Race an array of promises against a promise that rejects if nothing happens in the specified time window, but that can be postponed by signaling activity
https://github.com/pocesar/js-delayable-idle-abort-promise
abort abortable delayed inactivity inactivity-timer postpone promise promise-race promises race signaling-activity typescript typescript-definitions typescript-library
Last synced: 17 days ago
JSON representation
Race an array of promises against a promise that rejects if nothing happens in the specified time window, but that can be postponed by signaling activity
- Host: GitHub
- URL: https://github.com/pocesar/js-delayable-idle-abort-promise
- Owner: pocesar
- License: mit
- Created: 2020-02-17T02:00:25.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-02-19T05:30:10.000Z (over 4 years ago)
- Last Synced: 2024-04-28T05:48:07.288Z (7 months ago)
- Topics: abort, abortable, delayed, inactivity, inactivity-timer, postpone, promise, promise-race, promises, race, signaling-activity, typescript, typescript-definitions, typescript-library
- Language: TypeScript
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![NPM](https://img.shields.io/npm/l/async-atomic-store)](https://www.npmjs.com/package/delayable-idle-abort-promise)
[![npm](https://img.shields.io/npm/v/delayable-idle-abort-promise)](https://www.npmjs.com/package/delayable-idle-abort-promise)
[![npm](https://img.shields.io/npm/types/delayable-idle-abort-promise)](https://www.npmjs.com/package/delayable-idle-abort-promise)# delayable-idle-abort-promise
Race an array of promises against a promise that rejects if nothing happens in the specified time window, but that can be postponed by signaling activity
## Example
```js
import DelayAbort, { AbortError } from 'delayable-idle-abort-promise'const onePromise = (abort) => new Promise(() => {
setTimeout(abort, Math.round(Math.random() * 1000))
})const control = DelayAbort(1000)
setInterval(() => {
// postpone() will delay the "natural" internal interval,
// but not calls to abort()
control.postpone()
}, 100)try {
const result = await control.race([
onePromise(control.abort),
anotherPromise
])// do something with result
} catch (e) {
if (e instanceof AbortError) {
console.log(e.lastActivity, e.asDate())
}
}
```## License
MIT