Last change
on this file since bdd6491 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
782 bytes
|
Line | |
---|
1 | # promise-inflight
|
---|
2 |
|
---|
3 | One promise for multiple requests in flight to avoid async duplication
|
---|
4 |
|
---|
5 | ## USAGE
|
---|
6 |
|
---|
7 | ```javascript
|
---|
8 | const inflight = require('promise-inflight')
|
---|
9 |
|
---|
10 | // some request that does some stuff
|
---|
11 | function req(key) {
|
---|
12 | // key is any random string. like a url or filename or whatever.
|
---|
13 | return inflight(key, () => {
|
---|
14 | // this is where you'd fetch the url or whatever
|
---|
15 | return Promise.delay(100)
|
---|
16 | })
|
---|
17 | }
|
---|
18 |
|
---|
19 | // only assigns a single setTimeout
|
---|
20 | // when it dings, all thens get called with the same result. (There's only
|
---|
21 | // one underlying promise.)
|
---|
22 | req('foo').then(…)
|
---|
23 | req('foo').then(…)
|
---|
24 | req('foo').then(…)
|
---|
25 | req('foo').then(…)
|
---|
26 | ```
|
---|
27 |
|
---|
28 | ## SEE ALSO
|
---|
29 |
|
---|
30 | * [inflight](https://npmjs.com/package/inflight) - For the callback based function on which this is based.
|
---|
31 |
|
---|
32 | ## STILL NEEDS
|
---|
33 |
|
---|
34 | Tests!
|
---|
Note:
See
TracBrowser
for help on using the repository browser.