ebryn/backburner.js — pull request #22 by teddyzeenny (2013-05-21 18:34:22+00:00)
Title: Add beforeLoop and afterLoop callbacks

Added `beforeLoop` and `afterLoop` callbacks to backburner's options.

`beforeLoop` gets called whenever a run loop is started. It gets the currently starting loop as a first parameter, and the previous loop (if any) as a second parameter.

`afterLoop` gets called whenever a run loop is flushed. It gets the currently ending loop as a first parameter, and the next loop (i.e the wrapping loop if any) as a second parameter.

This is useful to run methods on start / end of run loops. Example use in Ember.js is keeping track of `Ember.run.currentRunLoop:`

```js
var backburner = new Backburner(['sync', 'actions'], {
beforeLoop: function(currentLoop, previousLoop) {
Ember.run.currentRunLoop = currentLoop;
}),
afterLoop: function(currentLoop, nextLoop) {
Ember.run.currentRunLoop = nextLoop;
}
});