ten::handle class
[scpubgit/TenDotTcl.git] / ten / ten.tcl
index 3798233..988915d 100644 (file)
@@ -197,6 +197,19 @@ snit::type ten::future {
     vwait "${selfns}::is_ready"
   }
 
+  method await_get {} {
+    $self retain
+    $self await_ready
+    if [$self is_failure] {
+      set err [$self failure]
+      $self free
+      error $err
+    }
+    set res [$self get]
+    $self free
+    return $res
+  }
+
   method retain {} {
     incr retain_count
   }
@@ -228,7 +241,7 @@ snit::type ten::read_channel {
       }
     } else {
       if [llength $options(-on_line_call)] {
-        while {[llength [set line [gets $chan]]] > 0} {
+        while {[string length [set line [gets $chan]]] > 0} {
           eval [concat $options(-on_line_call) [ list $line ]]
         }
       }
@@ -236,4 +249,17 @@ snit::type ten::read_channel {
   }
 }
 
+snit::type ten::handle {
+  option -connection
+  option -id
+
+  method call {name args} {
+    return [[$self start $name {*}$args] await_get]
+  }
+
+  method start {name args} {
+    $options(-connection) send call [json::write string $options(-id)] 0 [json::write string $name] {*}$args
+  }
+}
+
 package provide ten 0.0.1