al6x / synchronize

Write asynchronous code as if it's synchronous
http://alexeypetrushin.github.com/synchronize
316 stars 57 forks source link

using simple await defer with Firebase callback throws error #41

Open eladkarakuli opened 8 years ago

eladkarakuli commented 8 years ago

I'm trying to wrap and sync Firebase query methods as follows

sync.fiber(function() {
            var ref = sync.await(spotsRef.once('value', sync.defer()));
            console.log("ref", ref);
            return ref;
        });

And I get this error:

/home/my-app/node_modules/synchronize/sync.js:111
        fiber.throwInto(err)
              ^
[object Object]

API for Firebase [.once]() method

d3m3vilurr commented 8 years ago

.once method like this? https://github.com/firebase/firebase-util/blob/d3a5b7d95/test/e2e/NormalizedCollection.e2e.js#L89

if that, i think you should change to this :)

sync.fiber(function() {
    var defer = sync.defer();
    spotsRef.once('value',
                  function(s) { defer(null, s); }, // success callback
                  defer);                          // failure callback
    var ref = sync.await();
    console.log('ref', ref);
    return ref;
});
eladkarakuli commented 8 years ago

Thanks @d3m3vilurr! that worked.

bradvogel commented 8 years ago

Close this?

d3m3vilurr commented 8 years ago

@bradvogel Yea, this issue is not a bug. :) But only can close @alexeypetrushin or @eladkarakuli