Dashboard sipadu mbip
Você não pode selecionar mais de 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.

promise.js 344B

1234567891011121314151617181920
  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. }