Calls listener when a script sets or clears a timer, from the thread the script runs on, and returns a function that stops the listening.