rgrinberg / opium

Sinatra like web toolkit for OCaml
MIT License
755 stars 67 forks source link

Decouple `App.run` and `Lwt_main.run` #24

Closed avsm closed 9 years ago

avsm commented 9 years ago

I've got some Lwt actions to run in order to setup my handlers (a db connection to Irmin). It would be useful to decouple App.run from actually doing Lwt_main.run, as that would let me compose a few initialisation actions and then run Lwt_main.run on the result.

rgrinberg commented 9 years ago

Agreed, but I assume you mean App.start. App.run [1] doesn't call Lwt_min.run https://github.com/rgrinberg/opium/blob/master/rock/opium_rock.ml#L111

Although I have to make sure that the generated cmdliner command is aware of any custom initializations made (if you choose to use that)

rgrinberg commented 9 years ago

OK so App.start will no longer call Lwt_main.run for you as it's been pushed to run_command.

I will take a look at how to make the generated cmdliner more customizable.

avsm commented 9 years ago

I see what you mean about cmdliner. I'm working around it with the released version with two Lwt_main.run loops (which works, but feels risky), and will switch over to tracking Opium trunk.

rgrinberg commented 9 years ago

You may now use App.run_command' and launch the lwt event loop yourself to work around this.