factor out remote_object method
[scpubgit/TenDotTcl.git] / t / future.t
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 ""
11 set do_not_set_this ""
12
13 f1 on_ready [list set "[namespace current]::ready_args"]
14
15 f1 on_done [list set "[namespace current]::done_args"]
16
17 f1 on_fail [list set "[namespace current]::do_not_set_this"]
18
19 f1 done foo bar
20
21 ok {[f1 is_ready]} "Future ready"
22
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
31 is $do_not_set_this "" "on_fail not called"
32
33 is [f1 get] "foo bar" "get return ok"
34
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
59 done_testing