Posted to tcl by kyak at Thu Nov 08 18:16:02 GMT 2018view raw

  1. proc do_stuff {args} {
  2. if 1 $args
  3. # simulate blocking (e.g. in a http request)
  4. #after 2000
  5. # repeat this in 1 second:
  6. after 1000 [list do_stuff $args]
  7. }
  9. do_stuff puts "some stuff"
  10. do_stuff puts "some other stuff"
  11. after 10000 {set forever stop}
  12. vwait forever


Posted by avl at Mon Nov 12 12:32:44 GMT 2018 [text] [code]

inside the first call, args is, as if you had set it inside the proc as: set args {puts "some stuff"} ; that is what works with "if 1", which is almost equivalent to "eval". but then you create an after script that calls do_stuff with a single argument, rather than with separate arguments. line 6 should read: after 1000 [list do_stuff {*}$args] or alternatively: after 1000 [linsert $args 0 do_stuff] That said, it is not recommended to pass a script as separate words to a command. an even better aproach might be to turn "args" to a different name, and kick it off with do_stuff {puts "some stuff"}