I cannot get this to work, and starting to think I've misunderstood something fundamental. I've been through many examples, and I cannot see what I'm doing wrong.
Here is my promise:
myPromise = new Promise ( resolve => {
if (matchNew(id)) resolve();
})
myPromise.then( () => {
console.log('resolved');
})
matchNew() is a function that simply returns 'true' after completion of save to database. My console confirms this 'true' return happens, but code is not waiting for it, and the promise above never resolves.
Update
This is what I meant regarding the purpose of MatchNew(): It waits for confirmation from MongoDB that the write is successful, then then returns true.
function matchNew(id) {
/* do some stuff */
// update database
MongoPath.Match
.replaceOne( {'_id': m._id}, thisMatch, {writeConcern: { j: true}})
.then( (msg) => {
console.log(msg);
return true;
});
}
I want to ensure my main code is waiting until I get a return values from matchNew before continuing...