Permalink
Browse files

only use waiting before connection is established

  • Loading branch information...
1 parent e0576fb commit 7338e7ea329cd10f2d13279fe2a67433b27676d1 @vpulim committed Nov 16, 2011
Showing with 16 additions and 8 deletions.
  1. +15 −7 lib/collection.js
  2. +1 −1 package.json
View
@@ -31,13 +31,20 @@ Collection.prototype._connected = function(collection) {
self._collection = collection;
self._isConnected = true;
for (var i=0, cursor; cursor=self._waiting[i]; i++) {
- var fn = collection[cursor.command],
- c = fn.apply(collection, cursor.args);
- cursor._connected(c);
+ self._execute(cursor);
}
self._waiting = [];
};
+Collection.prototype._execute = function(cursor) {
+ var collection = this._collection;
+
+ if (!collection) return;
+ var fn = collection[cursor.command],
+ c = fn.apply(collection, cursor.args);
+ cursor._connected(c);
+}
+
Collection.functions = [
'insert',
'remove',
@@ -72,18 +79,19 @@ Collection.functions.forEach(function(name) {
isCursorOp = ~Collection.cursorFunctions.indexOf(name),
cursor = new Cursor(name, args);
- self._waiting.push(cursor);
-
if (self._isConnected) {
if (isCursorOp) {
process.nextTick(function() {
- self._connected(self._collection);
+ self._execute(cursor);
});
}
else {
- self._connected(self._collection);
+ self._execute(cursor);
}
}
+ else {
+ self._waiting.push(cursor);
+ }
return isCursorOp ? cursor : null;
};
View
@@ -1,6 +1,6 @@
{
"name":"mongode",
- "version":"0.0.12",
+ "version":"0.1.0",
"description":"A thin wrapper around node-mongodb-native with a simpler API",
"engines":{"node":">=0.4.0"},
"author":"Vinay Pulim <v@pulim.com>",

0 comments on commit 7338e7e

Please sign in to comment.