Projekt

Obecné

Profil

Stáhnout (344 Bajtů) Statistiky
| Větev: | Revize:
1
module.exports = thunkyp
2

    
3
function 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
}
(6-6/7)