From b97060bb7778a7ce01ac72948f3cd9bcef5d7ec9 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 26 Jun 2017 19:33:20 -0400 Subject: - Messages are now defined outside of the actor definition. --- stdlib/test/test/lux/concurrency/actor.lux | 39 ++++++++++++++++++------------ 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'stdlib/test') diff --git a/stdlib/test/test/lux/concurrency/actor.lux b/stdlib/test/test/lux/concurrency/actor.lux index 8ec792baf..a0e51cb09 100644 --- a/stdlib/test/test/lux/concurrency/actor.lux +++ b/stdlib/test/test/lux/concurrency/actor.lux @@ -8,46 +8,53 @@ ["R" result]) (concurrency ["P" promise "P/" Monad] ["T" task] - ["&" actor #+ actor:])) + ["&" actor #+ actor: message:])) lux/test) (actor: Counter Nat - ((count! state self) - Nat - (let [state' (n.inc state)] - (T;return [state' state']))) + ((handle message state self) + (do T;Monad + [#let [_ (log! "BEFORE")] + output (message state self) + #let [_ (log! "AFTER")]] + (wrap output))) - ([cause state] + ((stop cause state) (P/wrap (log! (if (ex;match? &;Killed cause) (format "Counter was killed: " (%n state)) cause))))) +(message: #export Counter + (count! [increment Nat] state self Nat) + (let [state' (n.+ increment state)] + (T;return [state' state']))) + (context: "Actors" ($_ seq - (test "Can check where an actor is alive." + (test "Can check if an actor is alive." (io;run (do Monad - [counter (new-Counter +0)] + [counter (new@Counter +0)] (wrap (&;alive? counter))))) (test "Can kill actors." (io;run (do Monad - [counter (new-Counter +0) + [counter (new@Counter +0) killed? (&;kill counter)] (wrap (and killed? (not (&;alive? counter))))))) (test "Can poison actors." (io;run (do Monad - [counter (new-Counter +0) + [counter (new@Counter +0) poisoned? (&;poison counter)] (wrap (and poisoned? (not (&;alive? counter))))))) (test "Cannot kill an already dead actor." (io;run (do Monad - [counter (new-Counter +0) + [counter (new@Counter +0) first-time (&;kill counter) second-time (&;kill counter)] (wrap (and first-time @@ -55,7 +62,7 @@ (test "Cannot poison an already dead actor." (io;run (do Monad - [counter (new-Counter +0) + [counter (new@Counter +0) first-time (&;kill counter) second-time (&;poison counter)] (wrap (and first-time @@ -63,10 +70,10 @@ (do P;Monad [result (do T;Monad - [#let [counter (io;run (new-Counter +0))] - output-1 (count! counter) - output-2 (count! counter) - output-3 (count! counter)] + [#let [counter (io;run (new@Counter +0))] + output-1 (count! +1 counter) + output-2 (count! +1 counter) + output-3 (count! +1 counter)] (wrap (and (n.= +1 output-1) (n.= +2 output-2) (n.= +3 output-3))))] -- cgit v1.2.3