settopending(f,fb) is the first function called, I am not sure if I did not write the callbacks correctly because applytransaction(t,f,fb) is never called. "First" and "Second" is printed but "Third" and "Fourth" are not printed. Did I incorrectly set up the callback that is supposed to call applytransaction(t,f,fb) or is there something else that is the problem?
function update(document,f,fb)
{
this.transactions.update(
{ _id: document._id, state: "initial" },
{
$set: {state: "pending"},
$currentDate: {lastModified: true}
}
);
console.log("Second")
}
function settopending(f,fb)
{
console.log("First");
var t = this.transactions.findOne( { state: "initial" } , function(err, document) {//CALLBACK
update(document,f,fb , function(err, document) {//CALLBACK
console.log("Third");
applytransaction(document,f,fb);
});
});
}
function applytransaction(t,f,fb)
{
console.log("Fourth");
x=fb(t.value);
y=f(t.value);
this.model.update(
{ _id: t.source, pendingTransactions: { $ne: t._id } },
{ $inc: { bal:x }, $push: { pendingTransactions: t._id } }
);
this.model.update(
{ _id: t.destination, pendingTransactions: { $ne: t._id } },
{ $inc: { bal: y }, $push: { pendingTransactions: t._id } }
)
}
function update(document,f,fb)- there's no callback argument declared nor any callback called -also,fandfbare never even used! ... doesthis.transactions.updateaccept a callback parameter?