mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
quick test for Lwt_actors
This commit is contained in:
parent
9c9a78c7a6
commit
5b9a7a2689
1 changed files with 33 additions and 0 deletions
33
tests/quick/actors.ml
Executable file
33
tests/quick/actors.ml
Executable file
|
|
@ -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 ()
|
||||
)
|
||||
|
||||
Loading…
Add table
Reference in a new issue