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

# task.
exiting = off

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

# 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
