 
 ms  = require("ms")
 Q   = require("q")
+global.setImmediate ||= process.nextTick
 
 
 # The browser event loop.


    # Someone (us) just started paying attention, start processing events
    if @listeners.length == 1
      process.nextTick =>
        if @active
          @active._eventQueue.resume()
          @run()

  # in the next tick, but makes sure waiters block for the function.
  next: (fn)->
    ++@expected
    setImmediate =>
      --@expected
      try
        fn()
