var inherits      = require('util').inherits
var EventEmitter  = require('events').EventEmitter;
var LockError     = require('lock/exception.js');

/**
 * Initialize and Register a new worker to the given queue.
 * --------------------------------------------------------
 * @constructor
 * @param {Queue} queue
 * @param {Object} options {
 *    types: {Array.<string>}
 * }
 */
function Worker(queue, options) {
  this.id = queue.workerRegister(options.types, this);
}
inherits(Worker, EventEmitter);

Worker.prototype.taskReady    = function(task) {
  queue.taskLock(this.id, task.id)

  .then(function(task) {

    this.emit(task.name, this.id, task);

  }.bind(this))

  // Ignore lock acquisition errors.
  .catch(LockError, function() {});
}


module.exports  = Worker;

@@ -1,101 +1,4 @@
-var inherits      = require('util').inherits%0Avar EventEmitter  = require('events').EventEmitter;%0A
 var 
@@ -369,41 +369,33 @@
 s);%0A
-%7D%0Ainherits(Worker, EventEmitter);
+  this.listeners  = %7B%7D;%0A%7D
 %0A%0AWo
@@ -638,16 +638,504 @@
 %7B%7D);%0A%7D%0A%0A
+Worker.prototype.hasListenerFor(evName) %7B%0A  return this.listeners.hasOwnProperty(evName);%0A%7D%0A%0AWorker.prototype.emit = function (evName) %7B%0A  cbArgs  = Array.prototype.slice.call(arguments, 1);%0A%0A  if(this.hasListenerFor(evName)) %7B%0A    this.listeners%5BevName%5D.apply(null, cbArgs);%0A  %7D%0A  return this;%0A%7D;%0A%0AWorker.prototype.on = function(evName, handler) %7B%0A  if(this.hasListenerFor(evName)) %7B%0A    throw new Error('DuplicateListener');%0A  %7D%0A  this.listeners%5BevName%5D  = handler;%0A%0A  return this;%0A%7D;%0A%0A
 %0Amodule.

implement single listener event handlers