1 USING: namespaces io tools.test threads kernel
2 concurrency.combinators concurrency.promises locals math
3 words calendar sequences ;
7 [ 2 "x" set ] "Test" spawn drop
8 [ 2 ] [ yield "x" get ] unit-test
9 [ ] [ [ flush ] "flush test" spawn drop flush ] unit-test
10 [ ] [ [ "Errors, errors" throw ] "error test" spawn drop ] unit-test
13 [ ] [ 0.3 sleep ] unit-test
14 [ "hey" sleep ] must-fail
16 [ 3 ] [ 3 self resume-with "Test suspend" suspend ] unit-test
18 [ f ] [ f get-global ] unit-test
20 { { 0 3 6 9 12 15 18 21 24 27 } } [
24 "i" [ yield 3 + ] tchange
30 :: spawn-namespace-test ( -- ? )
31 <promise> :> p gensym :> g
34 [ "x" get p fulfill ] "B" spawn drop
38 [ t ] [ spawn-namespace-test ] unit-test
40 [ "a" [ 1 1 + ] spawn 100 sleep ] must-fail
42 [ ] [ 0.1 seconds sleep ] unit-test
44 ! Test thread-local variables
49 [ 5 ] [ "x" tget ] unit-test
51 [ ] [ "x" [ 1 + ] tchange ] unit-test
53 [ 6 ] [ "x" tget ] unit-test
55 ! Are they truly thread-local?
56 [ "x" tget "p" get fulfill ] in-thread
58 [ f ] [ "p" get ?promise ] unit-test