factor out remote_object method
[scpubgit/TenDotTcl.git] / ten / ten.tcl
index a093a97..fed99af 100644 (file)
@@ -93,6 +93,11 @@ snit::type ten::connection {
     set send_this [ json::write array {*}$to_send ]
     puts $options(-send_to_fh) $send_this
   }
+
+  method remote_object {id} {
+    return [ten::handle %AUTO% -connection $self -id $id]
+  }
+
 }
 
 snit::type ten::future {
@@ -241,7 +246,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 ]]
         }
       }
@@ -249,4 +254,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