Posted to tcl by gps at Fri Mar 13 09:37:03 GMT 2009view raw
- proc A {sock} {
- yield
- while 1 {
- puts A
- gets $sock
- yield
- }
- }
- proc B {sock} {
- yield
- while 1 {
- puts B
- gets $sock
- yield
- }
- }
- proc C {sock} {
- yield
- while 1 {
- puts C
- gets $sock
- yield
- }
- }
- coroutine Charlie A ""
- coroutine The B ""
- coroutine Unicorn C ""
- set i 0
- set corolist [list Charlie The Unicorn]
- puts "Creating accept"
- proc accept {sock args} {
- global i corolist
- fileevent $sock readable [list [lindex $corolist $i] $sock]
- incr i
- if {$i >= [llength $corolist]} {
- set i 0
- }
- }
- socket -server accept 8080
- vwait forever