Artifact df37a68afbcbdd24ee842fff6c77d544d41d2858:
- File
packages/feed/lib/line.tcl
— part of check-in
[f6713683cd]
at
2020-05-13 09:21:51
on branch trunk
— feed line
fix eof handling
keep fix server startup (user: pooryorick size: 862)
#! /bin/env tclsh package require {ycl context} namespace import [yclprefix]::context::context namespace import [yclprefix]::context::derive+ proc line fh { set ns [context] $ns $ fh $fh $ns $ callbacks [list] $ns methods [namespace current]::\[a-z]* namespace eval $ns { namespace path [list [uplevel 1 {::namespace current}] {*}[ namespace path]] } return $ns } proc callback {self callback} { namespace eval $self [list lappend callbacks $callback] } proc feed self { set fh [set ${self}::fh] set count [gets $fh data] if {$count < 0} { if {[eof $fh]} { foreach callback [$self $ callbacks] { $callback done } } } else { incr ${self}::line foreach callback [$self $ callbacks] { $callback process from $self body $data } } return } proc go self { fileevent [set ${self}::fh] readable [list ${self} feed] }