Adding Lwt code to the Dream main loop

I don’t know if this is the best forum to ask questions about the Dream web framework. Please point me to the correct place, if necessary.

I’d like to add some code to the Dream main loop. This code should not run in the context of the request / response cycle, but it would connect to a PostgreSQL database and listen to events via a listen / notify channel. Dream’s job would be to react to certain database notifications by sending messages over connected websockets.

I can’t find an obvious way to inject my Lwt code into the call in Am I missing something?

I’m aware of the Git project aantron/dream-serve which, if I understand correctly, does a similar thing (sending websocket messages triggered by external events) by defining a custom Lwt_engine. This approach seems to be sparsely documented by the Lwt project (I’m happy to be proven wrong).

If Dream doesn’t allow extending it’s main loop, I’ll have to use two separate processes for websocket and PostgreSQL connections respectively, which communicate via HTTP.

Do you have any pointers for me? Thank you!

Prior to your call to (or @@ Dream.serve ..., depending), just schedule your other concurrent background tasks via Lwt.async.


This looks promising. Thank you.

Lwt.async is misleadingly named.



I see what you did there. :+1:t3: