]> gitweb.factorcode.org Git - factor.git/blob - basis/concurrency/exchangers/exchangers-tests.factor
factor: trim using lists
[factor.git] / basis / concurrency / exchangers / exchangers-tests.factor
1 USING: tools.test concurrency.exchangers
2 concurrency.count-downs concurrency.promises kernel
3 threads ;
4 FROM: sequences => 3append ;
5 IN: concurrency.exchangers.tests
6
7 :: exchanger-test ( -- string )
8     <exchanger> :> ex
9     2 <count-down> :> c
10     f :> v1!
11     f :> v2!
12     <promise> :> pr
13
14     [
15         c await
16         v1 ", " v2 3append pr fulfill
17     ] "Awaiter" spawn drop
18
19     [
20         "Goodbye world" ex exchange v1! c count-down
21     ] "Exchanger 1" spawn drop
22
23     [
24         "Hello world" ex exchange v2! c count-down
25     ] "Exchanger 2" spawn drop
26
27     pr ?promise ;
28
29 { "Hello world, Goodbye world" } [ exchanger-test ] unit-test