a function that returns the wrapped promise / 返回包装后的 promise
Example
leti = 1 constsingleton = createSingletonPromise(() =>Promise.resolve(i++))
constp1 = singleton() // fn only called once, i++ → 1 constp2 = singleton() // same promise returned, fn not called again console.log(p1 === p2) // true
Wrap a promise as a singleton, returning the same promise on multiple calls.
Through the
singleton.reset()method, you can reset the currently expired promise and wait for it to close normally.将一个 promise 包装为单例,在多次调用时,返回同一个 promise
通过
singleton.reset方法可以重置当前过期的 promise,并等待其正常关闭