/**
 * Tasker lib
 */

var Task = function (elements, handler) {
  this.elems = elements;
  if(typeof handler === 'function') {
    this._handler = handler;
  } else {
    this._handler = function (el, next, done) { next(null, el); };
  }
  this._fail = function () {};
  this._done = function () {};
};

Task.prototype.fail = function (func) {
  this._fail = func;
  return this;
};

Task.prototype.done = function (func) {
  this._done = func;
  return this;
};

Task.prototype.run = function () {
  var output = [];
  var self = this;

  once();

  // Run handler once on each item
  function once() {
    // Return results when no elements left
    if(!self.elems.length) return self._done(output);

    // Run function over each
    self._handler(
      // Element
      self.elems.shift(),
      // Next callback
      function (err, data) {
        if(err) return self._fail(err);
        if(typeof data !== 'undefined') output.push(data);
        return once();
      },
      // Exit callback
      function (err, data) {
        if(err) return self._fail(err);
        if(typeof data !== 'undefined') output.push(data);
        return self._done(output);
      }
    );
  }

  return this;
};

var tasker = function (elements, handler) {
  return new Task(elements, handler);
};

module.exports = tasker;

@@ -11,16 +11,457 @@
 ker lib%0A
+ *%0A * Usage:%0A *%0A * var tasker = require('tasker');%0A *%0A * tasker(elements, %5Bhandler%5D)%0A *   .fail(errCb)%0A *   .done(doneCb)%0A *   .run()%0A *%0A * Parameters:%0A *   - elements Array which items to process%0A *   - handler  Function processes each element%0A *     passes three parameters%0A *     (element, next, done)%0A *%0A * Chain methods:%0A *   - fail pass function to execute on fail%0A *     (err)%0A *   - done function to execute on done%0A *     (data)%0A *%0A
  */%0A%0Avar

Write simple docs about tasker lib