<commit_before>var q = require('q');

var Cursor = function (cursor, factory) {
  this._cursor = cursor;
  this._factory = factory;
};

Cursor.prototype.forEach = function (iterator) {
  var deferred = q.defer();
  this._cursor.forEach(
    function (doc) {
      return iterator(this._factory(doc));
    }.bind(this),
    function (err) {
      if (err) { return deferred.reject(err); }
      deferred.resolve();
    }
  );
  return deferred.promise;
};

Cursor.prototype.count = function (applySkipLimit, options) {
  return this._cursor.count(applySkipLimit, options);
};

Cursor.prototype.close = function () {
  return this._cursor.close();
};

Cursor.prototype.isClosed = function () {
  return this._cursor.isClosed();
};

Cursor.prototype.filter = function (filter) {
  this._cursor.filter(filter);
  return this;
};

Cursor.prototype.limit = function (limit) {
  this._cursor.limit(limit);
  return this;
};

Cursor.prototype.map = function (transform) {
  return this._cursor.map(function (doc) {
    return transform(this._factory(doc));
  }.bind(this));
};

Cursor.prototype.max = function (max) {
  this._cursor.max(max);
  return this;
};

Cursor.prototype.min = function (min) {
  this._cursor.min(min);
  return this;
};

Cursor.prototype.next = function () {
  return this._cursor
    .next()
    .then(function (doc) {
      return this._factory(doc);
    }.bind(this));
};

Cursor.prototype.skip = function (value) {
  this._cursor.skip(value);
  return this;
};

Cursor.prototype.sort = function (sortOrList, direction) {
  this._cursor.sort(sortOrList, direction);
  return this;
};

Cursor.prototype.toArray = function () {
  return this._cursor
    .toArray()
    .then(function (arr) {
      if (Array.isArray(arr)) {
        return arr.map(function (doc) {
          return this._factory(doc);
        }.bind(this));
      } else { return arr; }
    }.bind(this));
};

module.exports = Cursor;
<commit_msg>add a serial for each method<commit_after>var q = require('q');

var Cursor = function (cursor, factory) {
  this._cursor = cursor;
  this._factory = factory;
};

Cursor.prototype.forEach = function (iterator) {
  var deferred = q.defer();
  this._cursor.forEach(
    function (doc) {
      return iterator(this._factory(doc));
    }.bind(this),
    function (err) {
      if (err) { return deferred.reject(err); }
      deferred.resolve();
    }
  );
  return deferred.promise;
};

Cursor.prototype.count = function (applySkipLimit, options) {
  return this._cursor.count(applySkipLimit, options);
};

Cursor.prototype.close = function () {
  return this._cursor.close();
};

Cursor.prototype.isClosed = function () {
  return this._cursor.isClosed();
};

Cursor.prototype.filter = function (filter) {
  this._cursor.filter(filter);
  return this;
};

Cursor.prototype.limit = function (limit) {
  this._cursor.limit(limit);
  return this;
};

Cursor.prototype.map = function (transform) {
  return this._cursor.map(function (doc) {
    return transform(this._factory(doc));
  }.bind(this));
};

Cursor.prototype.max = function (max) {
  this._cursor.max(max);
  return this;
};

Cursor.prototype.min = function (min) {
  this._cursor.min(min);
  return this;
};

Cursor.prototype.next = function () {
  return this._cursor
    .next()
    .then(function (doc) {
      return this._factory(doc);
    }.bind(this));
};

Cursor.prototype.serialForEach = function (iterator) {
  var iterWrapper = function () {
    return this.next().then(function (item) {
      if(!item){ return; }
      return q(iterator(item)).then(iterWrapper);
    }.bind(this));
  }.bind(this);

  return iterWrapper();
};

Cursor.prototype.skip = function (value) {
  this._cursor.skip(value);
  return this;
};

Cursor.prototype.sort = function (sortOrList, direction) {
  this._cursor.sort(sortOrList, direction);
  return this;
};

Cursor.prototype.toArray = function () {
  return this._cursor
    .toArray()
    .then(function (arr) {
      if (Array.isArray(arr)) {
        return arr.map(function (doc) {
          return this._factory(doc);
        }.bind(this));
      } else { return arr; }
    }.bind(this));
};

module.exports = Cursor;

{'fraction_non_alphanumeric': 0.157476522995425, 'fraction_numerical': 0.0, 'mean_word_length': 3.4475374732334045, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3772769', 'n_tokens_mistral': 1336, 'n_tokens_neox': 1314, 'n_words': 274}