setTimeout is the usual way to call a function after some elapsed time:
If you want to trigger the same timeout at different points in your code, it soon gets messy detecting and cancelling the existing timeout and scheduling a new one.
ixfx’s Flow.timeout makes this a bit simpler. Once setup, calling start() schedules the timer, or resets if already scheduled. To cancel a started timeout, use cancel().
The callback can be cancelled and restarted. Restarting cancels the currently scheduled timeout, scheduling it anew.
Your callback function can use the elapsed time, if needed:
Data can be passed to the callback function when running .start():