Suppose some callback is registered for stdin.
fileevent stdin readable thatCallback
This means that during the execution of the update command it will evaluate thatCallback time after time while there is input available at stdin.
How can I make thatCallback to be evaluated only once during each call of update?
For each use of
update, any particular event handler will be executed only once. That’s because whatupdatedoes is to check for which event handlers are runnable (and which events are actually queued) and then executes all the ready ones, once. It doesn’t wait for further events to happen.Now, the
fileeventwill still be registered so that the next time the event loop is entered it will possibly be runnable again. If you want a once-onlyfileevent, de-register the handler while it is running. For example: