This repository has been archived on 2025-07-07. You can view files and clone it, but cannot push or open issues or pull requests.
Files
eternos/frontend/node_modules/thunky/promise.js
2025-01-13 09:33:52 +03:00

21 lines
344 B
JavaScript

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