You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
782 B

4 years ago
  1. # promise-inflight
  2. One promise for multiple requests in flight to avoid async duplication
  3. ## USAGE
  4. ```javascript
  5. const inflight = require('promise-inflight')
  6. // some request that does some stuff
  7. function req(key) {
  8. // key is any random string. like a url or filename or whatever.
  9. return inflight(key, () => {
  10. // this is where you'd fetch the url or whatever
  11. return Promise.delay(100)
  12. })
  13. }
  14. // only assigns a single setTimeout
  15. // when it dings, all thens get called with the same result. (There's only
  16. // one underlying promise.)
  17. req('foo').then(…)
  18. req('foo').then(…)
  19. req('foo').then(…)
  20. req('foo').then(…)
  21. ```
  22. ## SEE ALSO
  23. * [inflight](https://npmjs.com/package/inflight) - For the callback based function on which this is based.
  24. ## STILL NEEDS
  25. Tests!