From f04c3f0ecbb0b94c6931b268a12ca431f3ecdc53 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 3 Aug 2017 20:08:24 -0400 Subject: - Now, spaces automatically remove dead subscriptions after discovering them. --- stdlib/source/lux/concurrency/space.lux | 44 +++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 19 deletions(-) (limited to 'stdlib') diff --git a/stdlib/source/lux/concurrency/space.lux b/stdlib/source/lux/concurrency/space.lux index 7092e2395..8fe9fa583 100644 --- a/stdlib/source/lux/concurrency/space.lux +++ b/stdlib/source/lux/concurrency/space.lux @@ -7,7 +7,7 @@ ["T" task] ["A" actor #+ actor:]) (data [product] - (coll [list "L/" Functor])) + (coll [list "L/" Functor Fold])) [io #- run] [macro #+ with-gensyms] (macro [code] @@ -18,7 +18,7 @@ (with-expansions [ [e (A;Actor Top) (Space e)] - (as-is (-> (A;Actor s) (T;Task Unit)))] + (as-is (-> (A;Actor s) (T;Task Bool)))] (type: #export (Space e) (A;Actor (List (Ex [s] [(A;Actor s) ])))) @@ -56,13 +56,21 @@ (def: #export (emit event space sender) (All [e s] (-> e (Space e) (A;Actor s) (T;Task Unit))) (send-space (function [subscriptions _] - (exec (monad;map T;Monad - (function [[receiver action]] - (if (is (:! [] receiver) (:! [] sender)) - (T;return []) - (action [event sender space] receiver))) - subscriptions) - (T;return subscriptions))) + (exec (do T;Monad + [verdicts (monad;map @ + (function [(^@ sub [receiver action])] + (if (is (:! [] receiver) (:! [] sender)) + (T;return [true sub]) + (do @ + [sent? (action [event sender space] receiver)] + (wrap [sent? sub])))) + subscriptions)] + (T;return (L/fold (function [[sent? sub] survivors] + (if sent? + (#;Cons sub survivors) + survivors)) + (list) + verdicts))))) space)) (def: #export space @@ -136,15 +144,13 @@ (~ (csw;annotations annotations)) (All [(~@ (L/map code;local-symbol t-vars))] (;;Action (~ eventT) (~ stateT))) - (monad;do T;Monad - [(~ g!_) (T;from-promise - (_future - (A;send (function [(~ g!state) (~ g!receiverL)] - (: (T;Task (~ stateT)) - (do T;Monad - [] - (~ body)))) - (~ g!receiverL))))] - ((~' wrap) [])) + (T;from-promise + (_future + (A;send (function [(~ g!state) (~ g!receiverL)] + (: (T;Task (~ stateT)) + (monad;do T;Monad + [] + (~ body)))) + (~ g!receiverL)))) )))) ))) -- cgit v1.2.3