-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d7dfcb
commit 6d91535
Showing
4 changed files
with
27 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,28 @@ | ||
/** | ||
* Await a promise and save the result & errors so that they can be synchronously replayed later. | ||
* | ||
* | ||
* @template {any} T | ||
* @param {T} promise | ||
* | ||
* @param {T} promise | ||
* | ||
* @returns {Promise<()=> Awaited<T>>} | ||
*/ | ||
export async function buffer(promise) { | ||
/** @type {Awaited<T>} */ | ||
let resolvedWith; | ||
/** @type {Awaited<T>} */ | ||
let resolvedWith; | ||
|
||
/** @type {unknown} */ | ||
let rejectedWith; | ||
let rejected = false; | ||
/** @type {unknown} */ | ||
let rejectedWith; | ||
let rejected = false; | ||
|
||
try { | ||
resolvedWith = await promise; | ||
} catch (e) { | ||
rejectedWith = e; | ||
rejected = true; | ||
} | ||
|
||
try { | ||
resolvedWith = await promise; | ||
} catch (e) { | ||
rejectedWith = e; | ||
rejected = true; | ||
} | ||
|
||
return () => { | ||
if (rejected) throw rejectedWith; | ||
return resolvedWith; | ||
} | ||
} | ||
return () => { | ||
if (rejected) throw rejectedWith; | ||
return resolvedWith; | ||
}; | ||
} |