Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

21 linhas
344 B

  1. module.exports = thunkyp
  2. function thunkyp (fn) {
  3. let running = null
  4. return ready
  5. function ready () {
  6. if (running) return running
  7. const p = fn()
  8. if (!(p instanceof Promise)) running = Promise.resolve(p)
  9. else running = p
  10. running.catch(onerror)
  11. return running
  12. }
  13. function onerror () {
  14. running = null
  15. }
  16. }