var async = require('async');

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

    if (typeof(obj) != 'undefined') {
        throw new TypeError('obj argument must be an EventEmitter-like object');
    }
    if (typeof(ev) == 'undefined') {
        throw new TypeError('ev argument must be an event type string');
    }

    triggerCallbacks = function() {
        if (args !== null && callbacks.length > 0) {
            for(var i = 0; i < callbacks.length; ++i) {
                var callback = callbacks[i];

                async.nextTick(function() {
                    callback.apply(callback, args);
                });
            }
            callbacks = [];
            return true;
        } else {
            return false;
        }
    };

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

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

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

        if (args !== null) {
            triggerCallbacks();
        }
    };

    this.do = this.addCallback;

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

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

module.exports = DoWhen;

@@ -170,17 +170,17 @@
 of(obj) 
-!
+=
 = 'undef
@@ -231,26 +231,47 @@
 gument must 
-b
 e
+ither be a function or
  an EventEmi
@@ -395,19 +395,26 @@
 ent 
-type 
 string
+ or argument
 ');%0A
@@ -562,11 +562,11 @@
 th; 
+i
 ++
-i
 ) %7B%0A
@@ -679,31 +679,23 @@
     
-callback.apply(callback
+this.apply(this
 , ar
@@ -716,16 +716,31 @@
        %7D
+.bind(callback)
 );%0A     
@@ -889,24 +889,28 @@
 unction() %7B%0A
+    
     args = a
@@ -919,16 +919,20 @@
 uments;%0A
+    
     trig
@@ -946,32 +946,33 @@
 backs();%0A    %7D;%0A
+%0A
     this.on = fu
@@ -970,37 +970,39 @@
 s.on = function(
+_
 obj, 
+_
 ev) %7B%0A        ob
@@ -1003,60 +1003,337 @@
     
-obj.on(ev, objCallback);%0A    %7D;%0A    this.
+if (typeof(_obj) == 'undefined') %7B%0A            obj.on(ev, objCallback);%0A        %7D else %7B%0A            _obj.on(_ev, objCallback);%0A        %7D%0A    %7D;%0A%0A    this.call = functi
 on(
+_
 obj, 
+_
 ev)
+ %7B%0A        if (typeof(_obj) == 'undefined') %7B%0A            obj(ev, objCallback);%0A        %7D else %7B%0A            _obj(_ev, objCallback);%0A        %7D%0A    %7D
 ;%0A%0A 
@@ -1857,16 +1857,28 @@
 ports = 
+%7B'
 DoWhen
+': DoWhen%7D
 ;%0A

Fix param check, bind callback when iterating, and allow non-event style promises