! See http://factorcode.org/license.txt for BSD license.
!
! Channels - based on ideas from newsqueak
-USING: kernel sequences threads continuations
-random math accessors ;
+USING: accessors kernel random sequences threads ;
IN: channels
TUPLE: channel receivers senders ;
PRIVATE>
-M: channel to ( value channel -- )
+M: channel to
dup receivers>>
[ dup wait to ] [ nip (to) ] if-empty ;
-M: channel from ( channel -- value )
+M: channel from
[ self ] dip
notify senders>>
[ (from) ] unless-empty