Last active
July 13, 2024 10:45
-
-
Save pennane/2dabb3c2e45814dee2f8885be74d3f38 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| type TSettleResult<T> = [T, undefined] | [undefined, Error]; | |
| async function settle<T>(p: Promise<T>): Promise<TSettleResult<T>> { | |
| try { | |
| const x = await p; | |
| return [x, undefined]; | |
| } catch (e) { | |
| return [undefined, e]; | |
| } | |
| }; | |
| async function make_believe_go_lang() { | |
| const [value, error] = await settle(Promise.resolve(1234)); | |
| if (error) { | |
| return null; | |
| } | |
| return value; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment