Commit | Line | Data |
15e006dc |
1 | BEGIN { exec(tclsh => 't/tcl/harness.tcl' => $0) } |
2 | |
3 | package require ten |
4 | |
5 | ten::future f1 |
6 | |
7 | ok {![f1 is_ready]} "Future not yet ready" |
8 | |
9 | set ready_args "" |
10 | set done_args "" |
c7db0954 |
11 | set do_not_set_this "" |
15e006dc |
12 | |
b0dd2971 |
13 | f1 on_ready [list set "[namespace current]::ready_args"] |
15e006dc |
14 | |
b0dd2971 |
15 | f1 on_done [list set "[namespace current]::done_args"] |
15e006dc |
16 | |
c7db0954 |
17 | f1 on_fail [list set "[namespace current]::do_not_set_this"] |
18 | |
15e006dc |
19 | f1 done foo bar |
20 | |
21 | ok {[f1 is_ready]} "Future ready" |
22 | |
b0dd2971 |
23 | is $ready_args {::f1} "Future passed to ready" |
24 | |
25 | cmp_ok == [llength $done_args] 2 "Both args passed to done" |
26 | |
27 | is [lindex $done_args 0] foo "Right first arg" |
28 | |
29 | is [lindex $done_args 1] bar "Right second arg" |
30 | |
c7db0954 |
31 | is $do_not_set_this "" "on_fail not called" |
32 | |
b0dd2971 |
33 | is [f1 get] "foo bar" "get return ok" |
34 | |
c7db0954 |
35 | f1 destroy |
36 | |
37 | ten::future f2 |
38 | |
39 | f2 done one two three |
40 | |
41 | set done_args "" |
42 | |
43 | f2 on_done [list set "[namespace current]::done_args"] |
44 | |
45 | is $done_args "one two three" "on_done called on completed future" |
46 | |
47 | set ready_args "" |
48 | |
49 | f2 on_ready [list set "[namespace current]::ready_args"] |
50 | |
51 | is $ready_args {::f2} "on_ready called on completed future" |
52 | |
53 | set do_not_set_this "" |
54 | |
55 | f2 on_fail [list set "[namespace current]::do_not_set_this"] |
56 | |
57 | is $do_not_set_this "" "on_fail not called on completed future" |
58 | |
15e006dc |
59 | done_testing |