Created
January 13, 2024 12:16
-
-
Save genki/4d7b5aea1977b8f72bba928e4bfcba41 to your computer and use it in GitHub Desktop.
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
export const waiter: { | |
<T, R, A extends any[]>( | |
w:Waitable<T>, done:(x:T, ...args:A) => Promise<R>|R | |
): (...args:A) => Promise<R>; | |
<R, A extends any[], T=void|undefined>( | |
w:Waitable<T>, done:(...args:A) => Promise<R>|R | |
): (...args:A) => Promise<R>; | |
} = <T, R, A extends any[]>(w:Waitable<T>, done:{ | |
(x:T, ...args:A):Promise<R>|R; | |
(...args:A):Promise<R>|R; | |
}) => async (...args:A) => await w.wait( | |
x => x === undefined ? done(...args) : done(x, ...args) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment