I have a question about lwt's wait function and how I would use it in my own custom function which would return a 'a Lwt.t thread. First let's show you an example.
open Lwt_io
open Lwt.Infix
let i, o = Lwt_io.pipe()
let get_int () =
let t, w = Lwt.wait() in
(*what do I do here to provide the sleeping thread*)
(*with a possible integer reply*)
Lwt_io.read_int(i) >>= fun i -> Lwt.wakeup w i;
t
let ans = get_int()
In the above function I call wait to produce a sleeping thread plus its wakener but I'm unsure how to provide the sleeping thread with a possible integer reply and still be able to return a sleeping thread from the get_int function. I provided a line (Lwt_io.read_int(i) >>= fun i -> Lwt.wakeup w i;) which appears to work but I'm unsure if this the proper way to accomplish this. Any pointers or links or comments?
Note: I'm asking because adding Lwt_io.read_int(i) to the function is redundant. I could just eliminate the get_int function and just call Lwt_io.read_int(i) but I'm curious how you would do this without the redundancy.