Last active
March 11, 2024 11:40
-
-
Save zloyrusskiy/58481ba3e0dcf83cb0f89d34c7b27cf7 to your computer and use it in GitHub Desktop.
for Andrey async test
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
const delay = (ms: number) => { | |
return new Promise( resolve => setTimeout(resolve, ms) ); | |
} | |
const someAsync = async() => { | |
await delay(5000) | |
if (Math.random() < 0.5) { | |
throw Error("ppc") | |
} | |
} | |
console.log("before async"); | |
(async () => { | |
try { | |
console.log("begin async") | |
await someAsync(); | |
console.log("end async") | |
} catch { | |
process.exit(123) | |
} | |
})(); | |
console.log("after 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
{ | |
"dependencies": { | |
"ts-node": "^10.9.2" | |
} | |
} |
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
import cp from 'node:child_process' | |
console.log("started") | |
const resp = cp.spawnSync("node", ["-r", "ts-node/register", "child.ts"]) | |
console.log("finished with status", resp.status) | |
console.log(`output:\n--------\n${resp.stdout.toString('utf8')}\n--------\n`) |
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
node -r ts-node/register parent.ts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment