deno
deno copied to clipboard
RFC: Add `Deno.exitCode` support
Support a new Deno.exitCode API that allows user to define the would-be exitcode of the process w/o necessarily forcing an exit that instant (liek Deno.exit())
This is ideal for tasks that, on error condition, will want to exit as non-healthy but still need to perform some async cleanup tasks before actually exiting.
Not sure, but my first guess would be that the setter would just have to call into https://github.com/denoland/deno/blob/783533d2e354ad73356d7517b26293e48c10fc17/runtime/js/30_os.js#L76C5-L76C21
Because the runtime/js/30_os.js file is ESM, we can't actually match the same exitCode getter/setter API without converting all the exports into an object & then exporting that object as the default
I don't think that's desired, so instead I'm going to propose that we do this instead:
Deno.exit(); // unchanged
Deno.exit.code; //-> number | undefined
Deno.exit.code = 1; //-> void
At first I found it confusing to have Deno.exit as both a function and a setter bag, but after thinking about alternatives, I actually like it.
I'm just afraid that users will miss that exit can have its options set like that, because I don't think we have precedent for that "API style". Still I'm in favor of this. If we encounter a similar need in the future, we could use the same pattern.
I think this can be closed now.
Closed by #23609