add await_get and switch code to use it
[scpubgit/TenDotTcl.git] / t / readch.t
1 BEGIN { exec(tclsh => 't/tcl/harness.tcl' => $0) }
2
3 package require ten
4
5 set tfh [open {|t/bin/echo.pl} r+]
6
7 fconfigure $tfh -buffering line
8
9 set rch [ten::read_channel %AUTO% -fh $tfh]
10
11 proc line_cb {line} {
12   global got_line
13   set got_line $line
14 }
15
16 puts $tfh foo
17
18 $rch configure -on_line_call line_cb
19
20 global got_line
21
22 vwait got_line
23
24 is $got_line foo "Got line from read channel (send before set cb)"
25
26 puts $tfh bar
27
28 vwait got_line
29
30 is $got_line bar "Got line from read channel (send after set cb)"
31
32 $rch configure -on_close_call {global got_line; set got_line bye}
33
34 puts $tfh DIE
35
36 vwait got_line
37
38 is $got_line bye "Close handler called"
39
40 done_testing