Note I tested this on top of 109.34.00, then rebased to master but didn't compile since I don't have git versions of dependencies installed (which seem to be required).
Writer.transfer' is similar to Writer.transfer, but allowing to use async actions inside the given callback.
open Core.Std
open Async.Std
let main () =
let r = Pipe.of_list ["Foo"; "Bar"; "Baz"] in
Writer.with_file
?perm:(Some 0o600)
?append:(Some false)
?exclusive:(Some true)
"data.dat"
~f:(fun w ->
Writer.transfer' w r (
let rec loop q = match Queue.dequeue q with
| None -> return ()
| Some s ->
Writer.write_line w s;
Writer.flushed w >>= fun () ->
Writer.fdatasync w >>= fun () ->
loop q
in
loop))
>>| fun () ->
Shutdown.shutdown 0
;;
let _ = main () in
never_returns (Scheduler.go ())
Note I tested this on top of 109.34.00, then rebased to master but didn't compile since I don't have git versions of dependencies installed (which seem to be required).
Writer.transfer'
is similar toWriter.transfer
, but allowing to use async actions inside the given callback.See https://groups.google.com/forum/#!topic/ocaml-core/nFpAMKoWRYo for a related discussion.
Here's a demonstration:
Note this demonstration is not safe against power loss (even though
fdatasync
is used).