mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-22 16:35:14 +00:00
21 lines
344 B
JavaScript
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
|
|
}
|
|
}
|