diff --git a/src/lib/asyncSingleton.ts b/src/lib/asyncSingleton.ts index cd38dbb..86bb8e4 100644 --- a/src/lib/asyncSingleton.ts +++ b/src/lib/asyncSingleton.ts @@ -1,29 +1,15 @@ export function createAsyncSingleton (fn: () => Promise): () => Promise { let promise: Promise | null = null - let instance: T | null = null - async function fetch () { + return async function () { if (promise) { return promise } - promise = fn() return promise - .then(r => { - promise = null - return r - }) .catch(e => { promise = null - return e + throw e }) } - - return async function () { - if (instance) { - return instance - } - - return fetch() - } }