async function test() {
const proc = Bun.spawn(['echo', 'cheese'], {
cwd: process.cwd(),
stdout: 'inherit',
stderr: 'inherit'
});
await proc.exited;
console.log(proc.exitCode);
}
test();
console.log('foo');
In the above code, an asynchronous function is invoked which spawns a process. When the process exits, the exit code should be printed.
However, the lack of await on the call to test() appears to make this short-circuit, and anything after the internal await proc.exited is never processed. Instead, once the process is finished, the parent process terminates.
Adding an await to the call makes this behave as expected.
async function test() {
const proc = Bun.spawn(['echo', 'cheese'], {
cwd: process.cwd(),
stdout: 'inherit',
stderr: 'inherit'
});
await proc.exited;
console.log(proc.exitCode);
}
await test();
console.log('foo');
From my understanding, calling test() without await should still exhibit the same behaviour, with the exception that foo is not printed until after the promise resolves in the seond snippet.