异步或承诺全部,如果第一次失败,则全部拒绝 - 3个后方法调用
编辑。我需要调用adduser()
以接收userId
从数据库生成的回来。然后,我需要用userId
来调用addticket()
以接收ticketid
从数据库生成的返回。然后用用户ID
和ticketid
call 呼叫addtobooks
。这些都是POST方法,每个调用中我需要返回的唯一数据是他们的id
s,最后一个帖子方法将返回完整的数据。如果该过程中的任何一个失败,我是否可以处理所有帖子方法的方法?我已经看到了Promise的示例。所有可以做到这一点,但这全是为了获得方法。
Edited. I need to call addUser()
to receive the userId
back thats generated from the database. Then i need to call addTicket()
with the userId
to receive the ticketId
back thats generated from the database. Then finally call addToBooks
with the userId
and ticketId
. These are all post methods, the only data I need back from each call are their id
s, the last post method will return full data. Is there a way to handle this where I can fail all post methods if any one of the fails in the process? I've seen examples of promise.all that can do this but it was all for get methods.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试这样的尝试,按照您的函数名称示例:
这不使用
Promise.all
,但是由于您为我理解的示例,只需要userId 要完成其他两个操作,我认为这应该有效
You could try something like this, following your functions names example:
This doesn't use
Promise.all
, but since the example you are giving, to my understanding, only needs theuserId
to complete the other 2 operations, I think this should work