Async `print_endline` that returns a promise

Hey, I wonder whether there is a print_endline function in Async that returns a unit Deferred.t rather than simply unit. In Lwt_io they have a printl function that returns a promise. And in general, why would you want to have a promise on your write function? I would expect that to be instant. It is understandable why a read call would return a promise: you might spend several minutes waiting for a signal on your socket. What about the writes? I believe there might be some hardware issues that don’t return instantly.

I would expect that Writer.flushed plays this role here. Basically, this is a promise that is resolved once the writer has written everything.

I can’t answer the question about Async, but I can answer why Lwt_io.printl would return a promise:
What does it mean to “write”?
Is it written if it’s been put into Lwt’s buffer? Is it written if Lwt has flushed the buffer into the OS’s buffer? Is it written when the OS buffer has been written to the disk or network socket? Or is it when the disk has acknowledged its presence in its own buffers? Or when the other end of the TCP socket has returned an ACK?
And lastly, what happens if any of these buffers are full and block your write until space is available? All of these questions apply to Lwt_io.printl and the stdout socket it writes into.

2 Likes