I am trying to build a synchronous mongoose find. I adopted the use of deasync. https://www.npmjs.com/package/deasync
This is currently working for saves but it is not working for queries
exports.synchronousFind = function (instanceModel, query) {
var ready = false;
var result = null;
instanceModel.find(query, function (err, tenantUser) {
ready = true;
if (err) {
console.log(err);
} else {
result = tenantUser;
}
});
while (ready === false) {
require('deasync').runLoopOnce();
}
return result;
}
This part of the code
while (ready === false) {
require('deasync').runLoopOnce();
}
Just hangs forever and eventually it goes through. Does anyone have any ideas?