Skip to content

Instantly share code, notes, and snippets.

@seliopou
Last active Nov 17, 2020
Embed
What would you like to do?
(executable (name test_rng) (libraries async mirage-crypto-rng-async) (preprocess (pps ppx_jane)))
open Core
open Async
let main () =
let time_source = Synchronous_time_source.wall_clock () in
let print_next_alarm_time () =
let next_alarm_fires_in =
Option.map
(Synchronous_time_source.next_alarm_fires_at time_source)
~f:(fun next -> Time_ns.diff next (Synchronous_time_source.now time_source))
in
print_s [%message "" (next_alarm_fires_in : Time_ns.Span.t Option.t)];
in
print_next_alarm_time ();
Mirage_crypto_rng_async.initialize ();
print_next_alarm_time ();
let rand = Mirage_crypto_rng.generate 8 in
let bs = Bigstring.sub ~pos:rand.off ~len:rand.len rand.buffer in
print_endline (Bigstring.Hexdump.to_string_hum bs);
Synchronous_time_source.run_after
time_source
(Time_ns.Span.of_int_sec 1)
(fun () ->
print_next_alarm_time ();
Shutdown.shutdown 0)
;;
let () = ignore (Scheduler.go_main ~main () : never_returns)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment