USING: kernel threads vectors arrays sequences namespaces make
tools.test continuations deques strings math words match
quotations concurrency.messaging concurrency.mailboxes
-concurrency.count-downs accessors ;
+concurrency.count-downs concurrency.conditions accessors calendar ;
IN: concurrency.messaging.tests
[ ] [ my-mailbox data>> clear-deque ] unit-test
"sent" swap send-synchronous
] unit-test
+[ "received" ] [
+ [
+ receive "received" swap reply-synchronous
+ ] "Synchronous test" spawn
+ [ 100 milliseconds "sent" ] dip send-synchronous-timeout
+] unit-test
+
+[ [ 100 milliseconds sleep
+ receive "received" swap reply-synchronous ] "Synchronous test" spawn
+ [ 50 milliseconds "sent" ] dip send-synchronous-timeout
+] [ wait-timeout? ] must-fail-with
+
+
[ 1 3 2 ] [
1 self send
2 self send
data>>\r
] if ;\r
\r
+: send-synchronous-timeout ( timeout message thread -- reply ) \r
+ dup self eq? [\r
+ cannot-send-synchronous-to-self\r
+ ] [\r
+ [ <synchronous> dup ] dip send\r
+ '[ _ synchronous-reply? ] receive-if-timeout\r
+ data>>\r
+ ] if ; \r
+ \r
: reply-synchronous ( message synchronous -- )\r
[ <reply> ] keep sender>> send ;\r
\r