katoikia-app/web-ui/web-react/node_modules/thunky/promise.js

21 lines
344 B
JavaScript
Raw Normal View History

2022-07-06 04:15:11 +00:00
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
}
}