From 5b9a7a26891bc94a6d64860e16fcdb460bd2e01b Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 20 Nov 2014 01:04:11 +0100 Subject: [PATCH] quick test for Lwt_actors --- tests/quick/actors.ml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 tests/quick/actors.ml diff --git a/tests/quick/actors.ml b/tests/quick/actors.ml new file mode 100755 index 00000000..ef10daf7 --- /dev/null +++ b/tests/quick/actors.ml @@ -0,0 +1,33 @@ +#!/usr/bin/env ocaml +#use "tests/quick/.common.ml";; +#load "containers.cma";; +#require "lwt.unix";; +#load "containers_misc.cma";; +#load "containers_lwt.cma";; + +let (>>=) = Lwt.(>>=) + +module A = Containers_lwt.Lwt_actor + +let a = A.spawn + (fun _ (`Ping sender) -> + Lwt_io.printl "ping!" >>= fun () -> + Lwt_unix.sleep 1. >>= fun () -> + A.send sender `Pong + ) + +let b = A.spawn + (fun self -> function + | `Pong + | `Start -> + Lwt_io.printl "pong!" >>= fun () -> + Lwt_unix.sleep 1. >>= fun () -> + A.send a (`Ping self) + ) + +let () = Lwt_main.run ( + Lwt_io.printl "start" >>= fun () -> + A.send b `Start >>= fun () -> + A.wait_all () +) +