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