source: trip-planner-front/node_modules/thunky/promise.js@ ceaed42

Last change on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 344 bytes
RevLine 
[6a3a178]1module.exports = thunkyp
2
3function thunkyp (fn) {
4 let running = null
5
6 return ready
7
8 function ready () {
9 if (running) return running
10 const p = fn()
11 if (!(p instanceof Promise)) running = Promise.resolve(p)
12 else running = p
13 running.catch(onerror)
14 return running
15 }
16
17 function onerror () {
18 running = null
19 }
20}
Note: See TracBrowser for help on using the repository browser.