Using Lwt to interleave reads and writes

Hello there. I have almost no experience with Lwt, so excuse me if my comment is not relevant, but looking at it from a higher level point of view, maybe you could solve this by considering it as an instance of the Producer-Consumer problem.