One executor per datastore

pull/2/head
Louis Chatriot 12 years ago
parent 94e086dede
commit 74f0d8914e
  1. 11
      lib/datastore.js
  2. 13
      lib/executor.js
  3. 2
      package.json

@ -3,7 +3,7 @@ var fs = require('fs')
, customUtils = require('./customUtils')
, model = require('./model')
, async = require('async')
, executor = require('./executor')
, Executor = require('./executor')
;
@ -13,6 +13,7 @@ var fs = require('fs')
function Datastore (filename) {
this.filename = filename;
this.data = [];
this.executor = new Executor();
// We keep internally the number of lines in the datafile
// This will be used when/if I implement autocompacting when the datafile grows too big
@ -53,7 +54,7 @@ Datastore.prototype._loadDatabase = function (cb) {
};
Datastore.prototype.loadDatabase = function () {
executor.push({ this: this, fn: this._loadDatabase, arguments: arguments });
this.executor.push({ this: this, fn: this._loadDatabase, arguments: arguments });
};
@ -143,7 +144,7 @@ Datastore.prototype._insert = function (newDoc, cb) {
};
Datastore.prototype.insert = function () {
executor.push({ this: this, fn: this._insert, arguments: arguments });
this.executor.push({ this: this, fn: this._insert, arguments: arguments });
};
@ -285,7 +286,7 @@ Datastore.prototype._update = function (query, updateQuery, options, cb) {
]);
};
Datastore.prototype.update = function () {
executor.push({ this: this, fn: this._update, arguments: arguments });
this.executor.push({ this: this, fn: this._update, arguments: arguments });
};
@ -332,7 +333,7 @@ Datastore.prototype._remove = function (query, options, cb) {
});
};
Datastore.prototype.remove = function () {
executor.push({ this: this, fn: this._remove, arguments: arguments });
this.executor.push({ this: this, fn: this._remove, arguments: arguments });
};

@ -5,10 +5,10 @@
*/
var async = require('async')
, queue
;
executor = async.queue(function (task, cb) {
function Executor () {
this.queue = async.queue(function (task, cb) {
var callback
, lastArg = task.arguments[task.arguments.length - 1]
;
@ -31,8 +31,15 @@ executor = async.queue(function (task, cb) {
task.fn.apply(task.this, task.arguments);
}, 1);
}
Executor.prototype.push = function () {
this.queue.push.apply(this, arguments);
};
// Interface
module.exports = executor;
module.exports = Executor;

@ -1,6 +1,6 @@
{
"name": "nedb",
"version": "0.5.1",
"version": "0.5.2",
"author": {
"name": "tldr.io",
"email": "hello@tldr.io"

Loading…
Cancel
Save