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