var async = require('async');

var DoWhen = function(obj, ev) {
    var args,
        triggerCallbacks,
        objCallback,
        callbacks = [];

    triggerCallbacks = function() {
        for(var i = 0; i < callbacks.length; ++i) {
            var callback = callbacks.splice(i)[0];
        
            async.nextTick(function() {
                callback.apply(callback, args);
            });
        }
    };

    this.on = function(obj, ev) {
        objCallback = function() {
            args = arguments;
            triggerCallbacks();
        };
        obj.on(ev, objCallback);
    };
    this.on(obj, ev);

    this.off = function() {
        obj.removeCallback(objCallback);
    };

    this.addCallback = function(callback) {
        callbacks.push(callback);

        if (typeof(args) != 'undefined') {
            triggerCallbacks();
        }
    };

    this.do = this.addCallback;

    this.removeCallback = function(callback) {
        var i = callbacks.indexOf(callback);

        if (i != -1) {
            callbacks.splice(i);
            return true;
        } else {
            return false;
        }
    };
};

module.exports = DoWhen;

@@ -171,32 +171,65 @@
  = function() %7B%0A
+%09if (callbacks.length %3E 0) %7B%0A    
         for(var 
@@ -272,24 +272,28 @@
             
+    
 var callback
@@ -308,32 +308,18 @@
 acks
-.splice(i)%5B0%5D;%0A    
+%5Bi%5D;%0A%0A
     
-%0A
     
@@ -362,32 +362,36 @@
                 
+    
 callback.apply(c
@@ -418,16 +418,20 @@
         
+   
+ 
 %7D);%0A    
@@ -426,32 +426,67 @@
     %7D);%0A        
+    %7D%0A            callbacks = %5B%5D;%0A%09
 %7D%0A    %7D;%0A%0A    th
@@ -1112,16 +1112,19 @@
 splice(i
+, 1
 );%0A     

Fix splice for removeCallback, and avoid using splice for triggerCallbacks