문제가 있습니다. 기본적으로이 비동기 폭포가 완료되면 함수를 호출하고 싶습니다. 문제는 업데이트를 호출하지만 업데이트가 완료되기 전에 계속된다는 것입니다. 호출하려는 함수는 이미 업데이트 된이 데이터에 따라 다릅니다.
메시지가 전송되지 않았습니다. 그러나 결국 데이터베이스에서 업데이트됩니다.
function(arg1, arg2, callback) {
console.log('Updating current_pot with amountInPot');
current_pot.findOneAndUpdate(
{},
{'amountInPot': currentlyInPot},
function(err, current) {
if (err) {
throw err;
}
if (current != null) {
console.log('Updated current_pot amountInPot');
callback(null, 'c');
//This message should be sent before the callback continues!
}
});
}
모든 코드 :
async.waterfall([
function(callback) {
//remove from db
console.log('Add to local pot!');
currentlyInPot++;
peopleInPot.push([user.local.picture, message[1], user.local.email]);
callback(null, 'a', 'b');
},
function(arg1, arg2, callback) {
console.log('Updating persons credits');
callback(null, 'c', 'd');
},
function(arg1, arg2, callback) {
console.log('Adding new people to db');
var newPeople = new people_pot();
newPeople.email = user.local.email; //Auto increment
newPeople.picture = user.local.picture;
newPeople.message = message[1];
/** success starts */
newPeople.save(function(err) {
if (err) {
throw err;
}
});
callback(null, 'a', 'b');
},
function(arg1, arg2, callback) {
console.log('Updating current_pot with amountInPot');
current_pot.findOneAndUpdate({}, {
'amountInPot': currentlyInPot
},
function(err, current) {
if (err) {
throw err;
}
if (current != null) {
console.log('Updated current_pot amountInPot');
callback(null, 'c');
//This isn't getting completed before the loadpot is called!
}
});
}
], function(err, result) {
// result is 'e'
//add to db
});
newPeople.save
완료 될 때까지 기다리는 것을 잊었습니다 . 콜백 함수 호출을 콜백에 넣습니다. (부름)
/** success starts */
newPeople.save(function(err) {
callback(err, 'a', 'b');
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다