nodetcl icon indicating copy to clipboard operation
nodetcl copied to clipboard

Automatically invoke Tcl event loop only while necessary

Open bovine opened this issue 12 years ago • 2 comments

Currently, to keep the Tcl event loop processing, it is necessary for the Javascript side to ensure that interp.process_events() or interp.eval("update") is periodically processed. However, this is currently an implementation detail that the user should not have to be aware of.

The normal Node.JS behavior is to exit the "node" process once it has reached the end of the script file and there are no remaining event handlers installed or eligible to potentially run in the future.

It would be desirable to make interp.eval() silently install a hook that would periodically call interp.process_events() only as long as there are Tcl event handlers that could be triggered. This would allow the same normal Node.JS behavior of automatically exiting the process once all JavaScript and Tcl event handlers have completed, without any additional special handling code by the user.

The limiting factor currently seems to be that there is no way from the Tcl C API to determine if there are no more installed Tcl event handlers. There are some details in "man n Notifier" about the Tcl event sources, which might be relevant but this requires more research.

bovine avatar Nov 09 '11 21:11 bovine