ybogdanov / node-sync

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

Not work with promise-style library #36

Open hoan006 opened 10 years ago

hoan006 commented 10 years ago

I'm mainly using Mongoose for my project and I hope I can achieve something like this:

var person = Person.findOne.sync({name: "John"}); // not work
var count = Person.count.sync(); // works

Sadly, 'findOne' function uses promise (https://github.com/LearnBoost/mongoose/blob/3.8.x/lib/query.js#L991) and it breaks the node-sync, while 'count' doesn't use. Is there a way to support promise?

ybogdanov commented 10 years ago

Hi,

try this

var person = Person.findOne.sync(Person, {name: "John"}); // not work
airs0urce commented 8 years ago

@hoan006 I added ".syncp" and ".futurep" functions, they work with promises: https://github.com/airs0urce/node-sync/commit/c62f1a9023094adf6bc4f4134f9faa60e68bc94f

Not a brilliant because of copy/paste, but it works with functions that return Promise. I made this to be able to move to generators (co) or async/await in future.