Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sastan/inflight-barrier
One promise for multiple tasks in flight to avoid async duplication
https://github.com/sastan/inflight-barrier
Last synced: about 1 month ago
JSON representation
One promise for multiple tasks in flight to avoid async duplication
- Host: GitHub
- URL: https://github.com/sastan/inflight-barrier
- Owner: sastan
- License: mit
- Created: 2020-08-13T21:50:52.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2020-08-13T21:51:26.000Z (over 4 years ago)
- Last Synced: 2024-05-22T22:22:06.835Z (7 months ago)
- Language: TypeScript
- Size: 113 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# inflight-barrier
One promise for multiple requests in flight to avoid async duplication
## Usage
```js
import createInflightBarrier from 'inflight-barrier'const barrier = createInflightBarrier()
// some request that does some stuff
function req(key) {
// key can be any value which can be used as a key in a Map
return barrier(key, () => {
// this is where you'd fetch the url or whatever
return Promise.delay(100)
})
}// only assigns a single setTimeout
// when it dings, all thens get called with the same result. (There's only
// one underlying promise.)
req('foo').then(…)
req('foo').then(…)
req('foo').then(…)
req('foo').then(…)
```## See Also
- [promise-inflight](https://www.npmjs.com/package/promise-inflight)
- [inflight](https://www.npmjs.com/package/inflight)