Posted to tcl by kbk at Tue Feb 23 22:07:17 GMT 2021view raw

  1. namespace eval n {
  2.  
  3. proc schedule {x} {
  4.  
  5. after 1000 [namespace code [list handleEvent $x]]
  6.  
  7. }
  8.  
  9. proc handleEvent {x} {
  10.  
  11. variable done
  12. set done "handled event with data \"$x\""
  13.  
  14. }
  15.  
  16. proc awaitEvent {} {
  17.  
  18. variable done
  19. vwait [namespace current]::done
  20. return $done
  21.  
  22. }
  23.  
  24. }
  25.  
  26. n::schedule "hello, world"
  27. puts [n::awaitEvent]