I have some OCaml code that was being loaded by Ocisgen. Some of that code created expressions of type “Yojson.Safe.json Lwt.t” and stored them in a data structure. An endpoint I created for Ocsigen allowed me to examine those values periodically, that is, checking their state. Eventually, those expressions evolved to the “Return” state, and I could pull out a JSON value.
For various reasons, I want to run the same code with a different Web server, so that the code is called via SCGI. In this case, the expressions remain perpetually in a “Sleep” state. It seems that Ocsigen runs code in the Lwt monad for me, but that’s not true when using the other Web server. I could call “Lwt_main.run” on the expression before storing it in the data structure, but that would introduce synchronization, but then I lose the concurrency benefits of Lwt.
Is there a way to get these expressions to run “in the background” in what is otherwise non-Lwt-monadic code?