factor/basis/concurrency/exchangers/exchangers-tests.factor

30 lines
676 B
Factor
Raw Normal View History

USING: tools.test concurrency.exchangers
concurrency.count-downs concurrency.promises locals kernel
threads ;
FROM: sequences => 3append ;
IN: concurrency.exchangers.tests
2009-04-17 15:44:08 -04:00
:: exchanger-test ( -- string )
2009-10-27 22:50:31 -04:00
<exchanger> :> ex
2 <count-down> :> c
f :> v1!
f :> v2!
<promise> :> pr
2009-10-27 22:50:31 -04:00
[
c await
v1 ", " v2 3append pr fulfill
] "Awaiter" spawn drop
2009-10-27 22:50:31 -04:00
[
"Goodbye world" ex exchange v1! c count-down
] "Exchanger 1" spawn drop
2009-10-27 22:50:31 -04:00
[
"Hello world" ex exchange v2! c count-down
] "Exchanger 2" spawn drop
2009-10-27 22:50:31 -04:00
pr ?promise ;
[ "Hello world, Goodbye world" ] [ exchanger-test ] unit-test