Posted to tcl by aspect at Tue Apr 04 02:25:54 GMT 2017view raw

  1. proc coroeval { coro script } {
  2. uplevel 1 [format {%s;%s} \
  3. [list ::tcl::unsupported::inject $coro try [format { yield [try {%s} on error {} {}] } $script]] \
  4. $coro
  5. ]
  6. }
  7.  
  8. coroutine foo while 1 yield
  9. for {set i 0} {$i < 1000} {incr i} {
  10. coroeval foo {incr ::j}
  11. }
  12.