angular/angular.js — pull request #4500 by lrlopez (2013-10-17 19:32:39+00:00)
Title: feat($timeout): Add debouncing support to $timeout service

This feature allows resetting the timer on an ongoing `$timeout` promise. The implementation is really simple (see the diff) and fully backwards compatible. Documentation and tests are included.

The PR adds a fourth optional argument to `$timeout` which is the old promise to be reset.

With this feature you can debounce events. In the following example, `doRealSave()` will only be called 2 seconds after the last model change:
```js
var debounce;
var doRealSave = function() {
// Save model to DB
}
$scope.save = function() {
// debounce call for 2 seconds
debounce = $timeout(doRealSave, 2000, debounce);
}
```
And in the form:
```html

```

This PR has been extracted from a bigger one: https://github.com/angular/angular.js/pull/2129