1. Martin Jacobsson
  2. ocaml-core

Source

ocaml-core / base / async / examples / write_forever.ml

open Jane.Std
open Async.Std

let () =
  upon (Unix.openfile "/tmp/z.foo" ~mode:[`Creat; `Wronly] ~perm:0o0666)
    (fun fd ->
      let writer = Writer.create fd in
      let buf = String.create 1_048_576 in
      let rec loop i =
        eprintf "about to write %d\n" i;
        Writer.write writer buf;
        upon (Clock.after (sec 1.)) (fun () -> loop (i + 1));
      in
      loop 0
    )

let () = never_returns (Scheduler.go ());