node-sync icon indicating copy to clipboard operation
node-sync copied to clipboard

Not work with promise-style library

Open hoan006 opened this issue 11 years ago • 2 comments

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?

hoan006 avatar Jul 16 '14 09:07 hoan006

Hi,

try this

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

ybogdanov avatar Sep 16 '14 08:09 ybogdanov

@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.

airs0urce avatar Aug 20 '16 20:08 airs0urce