Running Async code in an exit handler

Can Async code run in an OCaml exit handler registered with `at_exit’?

The idea would be, schedule the Async code via “don’t_wait_for” and stuff its result in an ivar.

I’ve tried this, and the code doesn’t appear to run at all. Let’s guess the Async scheduler has terminated by the time we get to the time when `at_exit’ handlers are run. Is there a way to restart the scheduler, or create a temporary one?

Have you tried using something like Shutdown.at_shutdown?

In general, the Async scheduler expects to be started once, and then to be responsible for shutting down your program when it is finished.

Thanks, I was looking for something like that, but hadn’t found it.

I tried it, and it does exactly what I need!