ybogdanov / node-sync

Write simple and readable synchronous code in nodejs using fibers
MIT License
492 stars 70 forks source link

Sync not working with MongoJS #16

Closed GotEmB closed 12 years ago

GotEmB commented 12 years ago

I get errors like

.../DeCon/node_modules/sync/lib/sync.js:59
         if (yielded) fiber.run();
                            ^
TypeError: Object #<Object> has no method '_exec'
     at .../DeCon/node_modules/mongojs/index.js:47:7
     at Function.sync (.../node_modules/sync/lib/sync.js:66:8)
     at .../DeCon/web.js:95:63
     at .../DeCon/node_modules/sync/lib/sync.js:175:22

when trying to use something like db.collection.find(...).count.sync(null).

Source @ GotEmB/Decon/web.js. Here, lines 48, 72, 73 & 95 don't work.

ybogdanov commented 12 years ago
var collection = db.collection;
var cursor = collection.find.sync(collection);
var count = cursor.count.sync(cursor);
GotEmB commented 12 years ago
var cursor = collection.find.sync(collection);

Where would my query go?

ybogdanov commented 12 years ago
var cursor = collection.find.sync(collection, {your : 'query'}, {title : 1, content : 1});
GotEmB commented 12 years ago

Hey! Got it working by supplying the this to the .sync() function as you suggested.

I have a doubt now. In the model that I've adopted (GotEmB/DeCon/web.js), are the requests non-blocking? i.e. Do they run in separate fibers?