How to make a call to find() synchronous?

I have the following ES6 class and need to wait for the getAppearances function to return before the program flow continues, i.e. synchronously - how do I do this?

class MyClass {

    constructor() {
    }

    getAppearances(id) {
        return MyColl.find({
            ...    
        }).fetch();
    }

}
export { MyClass as default};


const c = new MyClass;
if( c.getAppearances > 0 ){
    ....
}
else{
    ...
}

use Meteor.wrapAsync

    //turn async function into synchronous
    asyncFunc = function (callback) {
            //async stuff here
        MyColl().find('stuff', function () {
            callback();
        });
    }
    syncFunc = Meteor.wrapAsync(asyncFunc);
    syncFunc();

Is callback necessary?

1 Like

yes, just call it wen you thing your sync function should end (can be in multiple places)

I discovered that .find() is synchronous by design.