I’m writing a program that will repeatedly spawn processes and use Lwt to asynchronously watch their stdout and wait for them to terminate. As I understand it, these watching tasks should be started with Lwt.async, but I also need to call Lwt_main.run somewhere to run the scheduler. Also, it seems like the task run by Lwt_main.run can’t terminate before the ones I started with Lwt.async (i.e. I can’t just do Lwt_main.run (Lwt_io.printl …) somewhere).
Currently I’m starting the stdout watch task with Lwt.async and the wait for termination with Lwt_main.run. This works, but it doesn’t seem ideal – it means I’ll make multiple (non-nested) calls to Lwt_main.run and produces a brittle structure. Should I be doing something like calling Lwt_main.run on a promise that will never be fulfilled instead?