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.
parttimejob/node_modules/thunky/promise.js

21 lines
344 B

module.exports = thunkyp
function thunkyp (fn) {
let running = null
return ready
function ready () {
if (running) return running
const p = fn()
if (!(p instanceof Promise)) running = Promise.resolve(p)
else running = p
running.catch(onerror)
return running
}
function onerror () {
running = null
}
}