From 54b6067f611ecb55a4aff7e0503285aa49db0365 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 24 Feb 2019 21:50:10 -0400 Subject: Got rid of the Task type (it just provided the same functionality as (error.with promise.monad)). --- .../source/test/lux/control/concurrency/actor.lux | 83 +++++++++++----------- 1 file changed, 42 insertions(+), 41 deletions(-) (limited to 'stdlib/source/test') diff --git a/stdlib/source/test/lux/control/concurrency/actor.lux b/stdlib/source/test/lux/control/concurrency/actor.lux index dba286b22..90c88744c 100644 --- a/stdlib/source/test/lux/control/concurrency/actor.lux +++ b/stdlib/source/test/lux/control/concurrency/actor.lux @@ -6,8 +6,7 @@ ["M" monad (#+ do Monad)] ["ex" exception] [concurrency - ["." promise ("#/." monad)] - ["T" task]]] + ["." promise ("#/." monad)]]] [data ["." error] [text @@ -21,7 +20,7 @@ Nat ((handle message state self) - (do T.monad + (do (error.with promise.monad) [#let [_ (log! "BEFORE")] output (message state self) #let [_ (log! "AFTER")]] @@ -35,47 +34,49 @@ (message: #export Counter (count! {increment Nat} state self Nat) (let [state' (n/+ increment state)] - (T.return [state' state']))) + (promise/wrap (#error.Success [state' state'])))) (def: #export test Test - (<| (_.context (%name (name-of /.Actor))) - ($_ _.and - (_.test "Can check if an actor is alive." - (io.run (do io.monad - [counter (new@Counter 0)] - (wrap (/.alive? counter))))) + (do r.monad + [_ (wrap [])] + (<| (_.context (%name (name-of /.Actor))) + ($_ _.and + (_.test "Can check if an actor is alive." + (io.run (do io.monad + [counter (new@Counter 0)] + (wrap (/.alive? counter))))) - (_.test "Can poison actors." - (io.run (do io.monad - [counter (new@Counter 0) - poisoned? (/.poison counter)] - (wrap (and poisoned? - (not (/.alive? counter))))))) - - (_.test "Cannot poison an already dead actor." - (io.run (do io.monad - [counter (new@Counter 0) - first-time (/.poison counter) - second-time (/.poison counter)] - (wrap (and first-time - (not second-time)))))) + (_.test "Can poison actors." + (io.run (do io.monad + [counter (new@Counter 0) + poisoned? (/.poison counter)] + (wrap (and poisoned? + (not (/.alive? counter))))))) + + (_.test "Cannot poison an already dead actor." + (io.run (do io.monad + [counter (new@Counter 0) + first-time (/.poison counter) + second-time (/.poison counter)] + (wrap (and first-time + (not second-time)))))) - (:: r.monad wrap - (do promise.monad - [result (do T.monad - [#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))))] - (_.assert "Can send messages to actors." - (case result - (#error.Success outcome) - outcome + (:: r.monad wrap + (do promise.monad + [result (do (error.with promise.monad) + [#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))))] + (_.assert "Can send messages to actors." + (case result + (#error.Success outcome) + outcome - (#error.Failure error) - #0)))) - ))) + (#error.Failure error) + #0)))) + )))) -- cgit v1.2.3