added send-synchronous-timeout word and tests

db4
Sascha Matzke 2009-08-22 16:46:45 +02:00
parent d9377625c5
commit 3351391e50
2 changed files with 23 additions and 1 deletions

View File

@ -3,7 +3,7 @@
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
@ -15,6 +15,19 @@ IN: concurrency.messaging.tests
"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

View File

@ -61,6 +61,15 @@ M: cannot-send-synchronous-to-self summary
data>>
] if ;
: send-synchronous-timeout ( timeout message thread -- reply )
dup self eq? [
cannot-send-synchronous-to-self
] [
[ <synchronous> dup ] dip send
'[ _ synchronous-reply? ] receive-if-timeout
data>>
] if ;
: reply-synchronous ( message synchronous -- )
[ <reply> ] keep sender>> send ;