想要 return 基于一系列其他 promise 完成的 promise
Want to return a promise based on a series of other promise completioen
这是我的代码:
var delete_card = function(){
stripe.customers.deleteCard(
this.service_id.stripe,
this.credit_card[0].stripe_id
)
.then(function(obj){
this.recipients.splice(0, 1);
return this.save()
})
}
条带化调用和保存调用return promises。
我如何 RETURN 来自 delete_card 方法的承诺?
我会像新的 Promise 一样将它们全部包装起来,然后 return 从那里得到一个 promise 吗?
我将如何构建它,以便我同时冒出错误和结果?
我希望能够像这样从调用者那里做一些事情:
delete_card
.then(...)
.catch(...)
然后继续写连锁承诺?
只是 return delete_card
函数中的承诺。
var delete_card = function(){
/************/
/**/return/**/ stripe.customers.deleteCard(
/************/
this.service_id.stripe,
this.credit_card[0].stripe_id
)
.then(function(obj){
this.recipients.splice(0, 1);
return this.save()
})
}
编辑: 我把 return
的添加位置变得非常明显,因为代码差异是如此微妙。
这是我的代码:
var delete_card = function(){
stripe.customers.deleteCard(
this.service_id.stripe,
this.credit_card[0].stripe_id
)
.then(function(obj){
this.recipients.splice(0, 1);
return this.save()
})
}
条带化调用和保存调用return promises。
我如何 RETURN 来自 delete_card 方法的承诺?
我会像新的 Promise 一样将它们全部包装起来,然后 return 从那里得到一个 promise 吗?
我将如何构建它,以便我同时冒出错误和结果?
我希望能够像这样从调用者那里做一些事情:
delete_card
.then(...)
.catch(...)
然后继续写连锁承诺?
只是 return delete_card
函数中的承诺。
var delete_card = function(){
/************/
/**/return/**/ stripe.customers.deleteCard(
/************/
this.service_id.stripe,
this.credit_card[0].stripe_id
)
.then(function(obj){
this.recipients.splice(0, 1);
return this.save()
})
}
编辑: 我把 return
的添加位置变得非常明显,因为代码差异是如此微妙。