【发布时间】:2017-01-18 02:31:41
【问题描述】:
settopending(f,fb) 是第一个调用的函数,我不确定我是否没有正确编写回调,因为从未调用过 applytransaction(t,f,fb)。打印“First”和“Second”,但不打印“Third”和“Fourth”。我是否错误地设置了应该调用 applytransaction(t,f,fb) 的回调,还是有其他问题?
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)- 没有声明回调参数,也没有调用任何回调 - 而且,f和fb甚至从未使用过! ...this.transactions.update是否接受回调参数?
标签: javascript node.js mongodb callback