Skip to content

Instantly share code, notes, and snippets.

@zloyrusskiy
Last active March 11, 2024 11:40
Show Gist options
  • Save zloyrusskiy/58481ba3e0dcf83cb0f89d34c7b27cf7 to your computer and use it in GitHub Desktop.
Save zloyrusskiy/58481ba3e0dcf83cb0f89d34c7b27cf7 to your computer and use it in GitHub Desktop.
for Andrey async test
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")
{
"dependencies": {
"ts-node": "^10.9.2"
}
}
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`)
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