1 package require Tcl 8.4
5 namespace eval ::ten:: {
6 set library [file dirname [info script]]
9 snit::type ten::connector::perl {
12 set conn_fh [open {|object-remote-node} r+]
13 set firstline [gets $conn_fh]
16 default { error "Expected Shere, got $firstline" }
19 set channel [ten::read_channel %AUTO% -fh $conn_fh]
22 ten::connection %AUTO% -send_to_fh $conn_fh -read_channel $channel
29 snit::type ten::connection {
35 $self configurelist $args
36 fconfigure $options(-send_to_fh) -buffering none
37 $options(-read_channel) configurelist [list \
38 -on_line_call [ mymethod Receive ] \
39 -on_close_call [ mymethod ChannelClosed ] \
43 method Receive {$line} {
47 method ChannelClosed {} {
51 method send {message_type args} {
52 set future [ten::future %AUTO%]
53 set call_args [concat $message_type $future $args]
57 snit::type ten::future {
66 error "Future $self already completed"
74 error "Future $self already completed"
80 method on_ready {cb_code} {
81 lappend callbacks [list ready $cb_code]
84 method on_done {cb_code} {
85 lappend callbacks [list done $cb_code]
88 method on_fail {cb_code} {
89 lappend callbacks [list fail $cb_code]
94 foreach cb $callbacks {
95 set cb_type [lindex $cb 0]
96 set cb_code [lindex $cb 1]
98 ready { eval [concat $cb_code $self] }
100 if ![$self is_failure] {
101 eval [concat $cb_code [list $result]]
105 if [$self is_failure] {
106 eval [concat $cb_code [list $failure]]
113 method AssertReady {} {
115 error "Future not ready"
119 method is_ready {} { return $is_ready }
123 if [$self is_failure] {
129 method is_failure {} {
131 if [llength $failure] {
143 vwait "${selfns}::is_ready"
147 snit::type ten::read_channel {
149 option -on_close_call
153 $self configurelist $args
154 fconfigure $options(-fh) -blocking 0
155 fileevent $options(-fh) readable [mymethod ReceiveData]
158 method ReceiveData {} {
159 set chan $options(-fh)
161 if [llength $options(-on_close_call)] {
162 eval $options(-on_close_call)
165 if [llength $options(-on_line_call)] {
166 while {[llength [set line [gets $chan]]] > 0} {
167 eval [concat $options(-on_line_call) $line]
174 package provide ten 0.0.1