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%]
54 [list list "str $message_type" "str $future"] $args
58 method Send {to_send} {
59 puts $options(-send_to_fh) [$self Serialize $to_send]
66 snit::type ten::future {
75 error "Future $self already completed"
83 error "Future $self already completed"
89 method on_ready {cb_code} {
91 eval [concat $cb_code $self]
93 lappend callbacks [list ready $cb_code]
97 method on_done {cb_code} {
98 if [llength $result] {
99 eval [concat $cb_code [list $result]]
101 lappend callbacks [list done $cb_code]
105 method on_fail {cb_code} {
106 if [llength $failure] {
107 eval [concat $cb_code [list $failure]]
109 lappend callbacks [list fail $cb_code]
113 method MarkReady {} {
115 foreach cb $callbacks {
116 set cb_type [lindex $cb 0]
117 set cb_code [lindex $cb 1]
119 ready { eval [concat $cb_code $self] }
121 if ![$self is_failure] {
122 eval [concat $cb_code [list $result]]
126 if [$self is_failure] {
127 eval [concat $cb_code [list $failure]]
134 method AssertReady {} {
136 error "Future not ready"
140 method is_ready {} { return $is_ready }
144 if [$self is_failure] {
150 method is_failure {} {
152 if [llength $failure] {
164 vwait "${selfns}::is_ready"
168 snit::type ten::read_channel {
170 option -on_close_call
174 $self configurelist $args
175 fconfigure $options(-fh) -blocking 0
176 fileevent $options(-fh) readable [mymethod ReceiveData]
179 method ReceiveData {} {
180 set chan $options(-fh)
182 if [llength $options(-on_close_call)] {
183 eval $options(-on_close_call)
186 if [llength $options(-on_line_call)] {
187 while {[llength [set line [gets $chan]]] > 0} {
188 eval [concat $options(-on_line_call) $line]
195 package provide ten 0.0.1