commit e729cd42687cbaf31a50dec37dcdd62f309c450b Author: Reynir Björnsson Date: Wed Aug 29 17:17:49 2018 +0200 Initial commit diff --git a/config.ml b/config.ml new file mode 100644 index 0000000..65912cf --- /dev/null +++ b/config.ml @@ -0,0 +1,9 @@ +open Mirage + +let main = + foreign + ~packages:[package "duration"; package "lwt_react"] + "Unikernel.Hello" (time @-> job) + +let () = + register "hello" [main $ default_time] diff --git a/unikernel.ml b/unikernel.ml new file mode 100644 index 0000000..96a94fe --- /dev/null +++ b/unikernel.ml @@ -0,0 +1,23 @@ +open Lwt.Infix + +module Hello (Time : Mirage_time_lwt.S) = struct + + let start _time = + let hello, run = + let open Lwt_react in + let e, send = E.create () in + let run () = + let rec loop n = + if n > 0 + then begin + send "hello"; + Time.sleep_ns (Duration.of_sec 1) >>= fun () -> + loop (n-1) + end else Lwt.return_unit in + loop 4 in + e, run in + let printer = Lwt_react.E.map (fun s -> Logs.info (fun f -> f "%s" s)) hello in + + run () + +end