rails/turbolinks — pull request #268 by dtao (2013-08-14 19:24:29+00:00)
Title: clear pending calls to setTimeout on page change

Say you have a call to `setTimeout` in a handler for the 'page:change' event. If you navigate between several pages quickly—faster than the delay you passed to `setTimeout`—the callback will be triggered multiple times. This change cancels any callbacks passed to `setTimeout` whenever the page changes.

It also includes a test page (timeout.html) where you can easily observe this behavior. Visit the page with and without the change. Without, clicking the 'This page' link a few times will result in multiple list items being appended to the DOM. With the change, only one item will be appended because all but the last call to `setTimeout` (that occurred after the last page change) are cleared.