already-ready tests
[scpubgit/TenDotTcl.git] / ten / ten.tcl
index 15be14d..0e22d50 100644 (file)
@@ -56,7 +56,7 @@ snit::type ten::connection {
 
 snit::type ten::future {
 
-  variable callbacks
+  variable callbacks ""
   variable is_ready 0
   variable result ""
   variable failure ""
@@ -78,15 +78,27 @@ snit::type ten::future {
   }
 
   method on_ready {cb_code} {
-    lappend callbacks [list ready $cb_code]
+    if [$self is_ready] {
+      eval [concat $cb_code $self]
+    } else {
+      lappend callbacks [list ready $cb_code]
+    }
   }
 
   method on_done {cb_code} {
-    lappend callbacks [list done $cb_code]
+    if [llength $result] {
+      eval [concat $cb_code [list $result]]
+    } else {
+      lappend callbacks [list done $cb_code]
+    }
   }
 
   method on_fail {cb_code} {
-    lappend callbacks [list fail $cb_code]
+    if [llength $failure] {
+      eval [concat $cb_code [list $failure]]
+    } else {
+      lappend callbacks [list fail $cb_code]
+    }
   }
 
   method MarkReady {} {