Posted to tcl by aspect at Mon Jul 04 12:13:16 GMT 2016view raw
- # after [medranocalvo] - 2016-05-19 @ 1255
- #
- # using both idleproc and afterproc leads to weird behaviour:
- # afterproc never gets past the first call to [update]!
- proc idleproc {} {
- while 1 {
- set i [info cmdcount]
- #puts "$i: idleproc in [info coroutine]"
- after idle [list [info coroutine]]
- yield
- update idletasks
- }
- }
- # unfortunately, this needs to be constantly putting itself
- # at the front of the event queue so that it can wake up
- # in time to process any events that have inserted themselves
- # since. So it never sleeps, which is a shame.
- proc afterproc {} {
- while 1 {
- set i [info cmdcount]
- puts "$i: afterproc in [info coroutine]: yielding"
- after 0 [list [info coroutine]]
- yield
- puts "$i: afterproc in [info coroutine]: after yield"
- update
- puts "$i: afterproc in [info coroutine]: after update"
- }
- }
- #coroutine idlecoro idleproc
- coroutine aftercoro afterproc
- after idle {
- puts i:[info coroutine]
- after idle {puts ii:[info coroutine]}
- }
- after idle {after 0 {puts i0:\ [info coroutine]}}
- after 0 {after idle {puts 0i:\ [info coroutine]}}
- after 0 {puts 0:[info coroutine]}
- after 100 {
- after idle {
- puts i:[info coroutine]
- after idle {puts Xii:\ [info coroutine]}
- }
- after idle {after 100 {puts XiX:\ [info coroutine]}}
- after 100 {after idle {puts XXi:\ [info coroutine]}}
- after 100 {puts XX:\ [info coroutine]}
- }
- set s [socket -async google.com 443]
- fileevent $s writable [list apply {{s args} {
- puts "writable: [info coroutine]"
- close $s
- }} $s]
- vwait forever