I can’t figure out how to wrap geocoder so it is synchronous…
import geocoder from 'geocoder';
let geoCoderAsync = Meteor.wrapAsync(geocoder.reverseGeocode);
let result = geoCoderAsync(data.location.latitude, data.location.longitude, function ( err, response ) {
if (err) { console.log(err); }
return result
});
console.log(result)
this outputs
TypeError: Cannot read property ‘reverseGeocode’ of undefined
To the best of my understanding, there are at least 2 ways of dealing with sync data in Meteor: Fibers and Promises. Fibers are native to Node.js and work only on server, whereas Promises (with async/await syntax) is a super-new JavaScript approach and should technically work on both server and client. Specifically wrapAsync is based on Fibers and actually works only on server. So depending on your requirements, if, for example, you do not need client synchronous code, you can perfectly live with Fibers.
I can give you an example of a working sync method with wrapAsync, maybe it can guide you into right direction (the method should run only on server):
When investigating Promises I could not properly show the result of a promise in a helper with native Meteor and did not want to install any third party packages. If someone could share a working simple example that can be easily repeated/followed, would be good.
You have to use resolve reject. Simply go online or even better buy a book (the secrets of the javascript ninja, or eloquent javascript), and practice with promises. Knowing javascript grammar is important to avoid such problems, as it’s a bit tricky.
I’m at work, sorry if I can’t help you better, here’s one of my promises:
W-e-e-e-e-ll … not always. It all depends on what the wrapped method expects in the way of binding. Having said that, I’ve found that 90% of the time it’s fine with it, whether or not it “needs” it.
So, I took a chance that it would be OK. You should try without the binding to see if it still works.