| ▲ | gtowey 2 days ago |
| Finally isn't bullet proof. If you execute a promise in a try block and it happens to end without resolving, the finally block will be never be executed. Fun stuff. |
|
| ▲ | anttiharju 2 days ago | parent | next [-] |
| defer isn't bullet proof either. I think there's a linter about it and os.Exit. One can just wrap os.Exit in a helper to get the expected behaviour. |
| |
| ▲ | gtowey a day ago | parent | next [-] | | I would expect to have a method that explicitly stops program execution immediately without further side effects. An unresolved promise that causes other code to be skipped while program execution continues after the block is, well, unintuitive to say the least. | |
| ▲ | Joker_vD 2 days ago | parent | prev [-] | | Also, if you pull the power plug, neither finally blocks nor defers would run. I personally consider it a clear and obvious deficiency in the semantics (and the implementations) of those programming languages but everybody refuses to listen to me. | | |
| ▲ | gtowey a day ago | parent [-] | | Back in the days of spinning rust, we had RAID controller cards with batteries, so that if someone pulled the plug, there would be enough power to keep the drives going until any buffered writes were completed. I certainly wouldn't mind if modern servers had something similar to make sure programs could stop gracefully. But then that doesn't help if you have a hardware failure... | | |
|
|
|
| ▲ | cute_boi 2 days ago | parent | prev [-] |
| I think this is correct behavior. ```
async function run() {
try {
await new Promise(() => {
// The executor function finishes,
// but it never calls resolve() or reject().
});
} finally {
console.log("cleanup");
}
}
``` I never expect cleanup to be logged. |