aboutsummaryrefslogtreecommitdiff
path: root/examples/vwaitsignal.tcl
blob: d59879a7622c86386bce3c6ded7cdc9a44063afa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# In lieu of some proper unit tests, this example
# checks that vwait can be interrupted by handled signals

set f [open "/dev/urandom" r]

set count 0

$f ndelay 1

signal handle SIGALRM

$f readable {
	incr count [string bytelength [read $f 100]]
}


set start [clock millis]

# Even though nothing sets 'done', vwait will return on the signal
alarm 0.5
vwait -signal done

set end [clock millis]
puts "Read $count bytes and received [signal check -clear] after $($end - $start)ms"

$f close