I am getting an object from a stream and timing it like so:
let t1 = Time_now.nanoseconds_since_unix_epoch () in
let* msg_event = Lwt_stream.get s.msgs in
let t2 = Time_now.nanoseconds_since_unix_epoch () in
I also tried this, which had the same behaviour:
let stream_get q =
try (
let* e = Lwt_stream.next q in
Lwt.return_some e
)
with Lwt_stream.Empty -> Lwt.return_none
Most of the time this operation takes very little time, but sometimes it will take a long time to return as it appears to be waiting for an element to be added to the stream (in another thread). I want the function to return None immediately if the queue is empty rather than waiting. How can I do this?