-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: should wait a while before clearing resource
- Loading branch information
1 parent
503169f
commit ad99461
Showing
2 changed files
with
101 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Basically Promise.withResolvers() | ||
* @template T | ||
* @see https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers | ||
*/ | ||
export function promiseWithResolvers() { | ||
/** @type {(value: T | PromiseLike<T>) => void} */ | ||
let res = () => {} | ||
/** @type {(reason?: Error) => void} */ | ||
let rej = () => {} | ||
/** @type {Promise<T>} */ | ||
const promise = new Promise((resolve, reject) => { | ||
res = resolve | ||
rej = reject | ||
}) | ||
return { promise, resolve: res, reject: rej } | ||
} |
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