 
     false
 
-  _requestComplete: ->
-    @_emitter.emit "finish", @currentJob
+  _jobComplete: (job) ->
+    @_emitter.emit "finish", job
 
-    @currentJob = null
+    index = @runningJobs.indexOf(job)
+    @runningJobs.splice(index, 1)
+
     @_checkQueue()

  @HIGH: 2
  @VERY_HIGH: 3

  constructor: ->
    @jobs = []
    @currentJob = null
    @_emitter = new Emitter

  enqueue: (request, priority) ->

  off: (args...) -> @_emitter.off args...

  _checkQueue: ->
    return if @runningJobs.length >= @workerCount

    while @jobs.length > 0 and @runningJobs.length < @workerCount
      nextJob = @_dequeue()
      @_emitter.emit "start", nextJob
      @runningJobs.push nextJob

      request = nextJob.request
      request.on "complete", @_jobComplete.bind(this, nextJob)
      request.send()

  _dequeue: ->
    return null if @jobs.length is 0
