diff options
author | Eduardo Julian | 2017-08-03 20:08:24 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-08-03 20:08:24 -0400 |
commit | f04c3f0ecbb0b94c6931b268a12ca431f3ecdc53 (patch) | |
tree | 5897aa459b3b977d132f8467023468f8987980a9 /stdlib | |
parent | cb129986c4f97ae947ef582e9a5417db83b28e4c (diff) |
- Now, spaces automatically remove dead subscriptions after discovering them.
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/concurrency/space.lux | 44 |
1 files changed, 25 insertions, 19 deletions
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<List>])) + (coll [list "L/" Functor<List> Fold<List>])) [io #- run] [macro #+ with-gensyms] (macro [code] @@ -18,7 +18,7 @@ (with-expansions [<Event> [e (A;Actor Top) (Space e)] - <Action> (as-is (-> <Event> (A;Actor s) (T;Task Unit)))] + <Action> (as-is (-> <Event> (A;Actor s) (T;Task Bool)))] (type: #export (Space e) (A;Actor (List (Ex [s] [(A;Actor s) <Action>])))) @@ -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<Task> - (function [[receiver action]] - (if (is (:! [] receiver) (:! [] sender)) - (T;return []) - (action [event sender space] receiver))) - subscriptions) - (T;return subscriptions))) + (exec (do T;Monad<Task> + [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<Task> - [(~ g!_) (T;from-promise - (_future - (A;send (function [(~ g!state) (~ g!receiverL)] - (: (T;Task (~ stateT)) - (do T;Monad<Task> - [] - (~ body)))) - (~ g!receiverL))))] - ((~' wrap) [])) + (T;from-promise + (_future + (A;send (function [(~ g!state) (~ g!receiverL)] + (: (T;Task (~ stateT)) + (monad;do T;Monad<Task> + [] + (~ body)))) + (~ g!receiverL)))) )))) ))) |