]> gitweb.factorcode.org Git - factor.git/commitdiff
concurrency.distributed: simplify a bit, mostly because...
authorJohn Benediktsson <mrjbq7@gmail.com>
Sat, 20 Jan 2018 16:16:25 +0000 (08:16 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sat, 20 Jan 2018 16:16:25 +0000 (08:16 -0800)
... I'm not a fan of thd instead of thread, and it seemed (to me)
a little cleaner inlining assoc instead of using get/set words.

basis/concurrency/distributed/distributed.factor

index 60b7dc87b04346b9a62e4b7d5f7e8983cade0a10..f046cdb394a216311cf01ec82b7141c8d898186c 100644 (file)
@@ -16,14 +16,6 @@ IN: concurrency.distributed
 : thread-connections ( -- hash )
     \ thread-connections get-global ;
 
-: get-thd-conn ( thread -- connection/f )
-    thread-connections at ;
-
-: set-thd-conn ( thread connection/f -- )
-    [ swap thread-connections set-at ] [
-        thread-connections delete-at
-    ] if* ;
-
 PRIVATE>
 
 : register-remote-thread ( thread name -- )
@@ -60,10 +52,12 @@ TUPLE: connection remote stream local ;
 C: <connection> connection
 
 : connect ( remote-thread -- )
-    dup node>> dup binary <client> <connection> set-thd-conn ;
+    [ node>> dup binary <client> <connection> ]
+    [ thread-connections set-at ] bi ;
 
 : disconnect ( remote-thread -- )
-    dup get-thd-conn [ stream>> dispose ] when* f set-thd-conn ;
+    [ thread-connections at [ stream>> dispose ] when* ]
+    [ thread-connections delete-at ] bi ;
 
 : with-connection ( remote-thread quot -- )
     '[ connect @ ] over [ disconnect ] curry [ ] cleanup ; inline
@@ -75,7 +69,7 @@ C: <connection> connection
     stream>> [ serialize flush ] with-stream* ;
 
 M: remote-thread send ( message thread -- )
-    [ id>> 2array ] [ node>> ] [ get-thd-conn ] tri
+    [ id>> 2array ] [ node>> ] [ thread-connections at ] tri
     [ nip send-to-connection ] [ send-remote-message ] if* ;
 
 M: thread (serialize) ( obj -- )