 # task.
 exiting = off
 
+close_callback = null
+
 # Keep current process's all registered workers an array, rely on this array to
 # count cleaned workers on exiting.
 registered_workers = []


  # **Private** method. Wait if there're queues still working, or exit the
  # process immediately.
  unregist: =>
    @redis.hdel @key('WORKERS'), @id, (err, res) =>
      workers.splice workers.indexOf(@), 1
      process.exit() unless workers.length

# If there's no registered workers, exit directly.
first_time = on
clean_up = ->
  log_registered_workers() unless first_time
  first_time = off
  return setTimeout((-> if close_callback then close_callback() else process.exit()), 0) unless workers.length
  exiting = on
  for worker in workers
    worker.unregist() if worker.is_idling
