Created
July 30, 2021 18:18
-
-
Save concavelenz/b17088c42cebf2367e7c5be3f618331e to your computer and use it in GitHub Desktop.
zone + async
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
async function myCode() { | |
const value = await doSomething(); | |
const value2 = await somethingElse(value) | |
return value2 + 1; | |
} | |
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
async function myCode() { | |
const restoreZone = saveCurrentZone(); | |
try { | |
const value = restoreZone(await doSomething()); | |
const value2 = restoreZone(await somethingElse(value)); | |
return value2 + 1; | |
} finally { | |
restoreZone(closeToken); | |
} | |
} |
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
// global support | |
function saveCurrentZone() { ... } | |
const closeToken = {}; // globally unique object to use as a token |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment