add await_get and switch code to use it
[scpubgit/TenDotTcl.git] / t / future.t
index ef9ae98..1f61397 100644 (file)
@@ -8,13 +8,52 @@ ok {![f1 is_ready]} "Future not yet ready"
 
 set ready_args ""
 set done_args ""
+set do_not_set_this ""
 
-f1 on_ready {set "[namespace current]::ready_args"}
+f1 on_ready [list set "[namespace current]::ready_args"]
 
-f1 on_done {set "[namespace current]::done_args"}
+f1 on_done [list set "[namespace current]::done_args"]
+
+f1 on_fail [list set "[namespace current]::do_not_set_this"]
 
 f1 done foo bar
 
 ok {[f1 is_ready]} "Future ready"
 
+is $ready_args {::f1} "Future passed to ready"
+
+cmp_ok == [llength $done_args] 2 "Both args passed to done"
+
+is [lindex $done_args 0] foo "Right first arg"
+
+is [lindex $done_args 1] bar "Right second arg"
+
+is $do_not_set_this "" "on_fail not called"
+
+is [f1 get] "foo bar" "get return ok"
+
+f1 destroy
+
+ten::future f2
+
+f2 done one two three
+
+set done_args ""
+
+f2 on_done [list set "[namespace current]::done_args"]
+
+is $done_args "one two three" "on_done called on completed future"
+
+set ready_args ""
+
+f2 on_ready [list set "[namespace current]::ready_args"]
+
+is $ready_args {::f2} "on_ready called on completed future"
+
+set do_not_set_this ""
+
+f2 on_fail [list set "[namespace current]::do_not_set_this"]
+
+is $do_not_set_this "" "on_fail not called on completed future"
+
 done_testing