我目前正在与PG-承诺,蓝鸟发电机:PG-承诺:空话
function * getOrRegisterCurrentFriendIfProvided(t)
应该返回一个空的承诺(如果t.ctx.context是不确定的)
NB :
yield new Promise(function (resolve) { resolve({}) });
或调用另一个函数(即提供了一个结果)::
yield t.task.call(params.friend,anotherFunction);
在纯蓝鸟一个例子
任何方式来表达我的空承诺pg-promise(不使用像t.none(“BYPASS查询”))的查询?
与下面的示例中,当我这样做:
db.task(getOrRegisterCurrentFriendIfProvided)
.then(function(result){
console.log(result) // gives me undefined
})
我不确定。我相信,这个问题occurer时t.ctx.context未定义
编辑:全码:
function * getOrRegisterCurrentFriendIfProvided(t) {
let params = t.ctx.context;
if (params.hasOwnProperty("friend")) {
yield t.task.call(params.friend,anotherFunction);
} else {
// returns a empty result ({}) promise , just to make promise chain not angry
yield new Promise(function (resolve) { resolve({}) });
}
}
您需要为您的问题添加'getOrRegisterCurrentFriendIfProvided'实现,否则不可能知道您在做什么以及问题出在哪里。 –
刚刚添加并找到了解决方案,但它可能不是最好的解决方案 – jy95
问题现在已经很明显 - 您的回调中任何地方都没有返回任何东西,那么您期望从任务中返回什么? :) –