gpt4 book ai didi

angularjs - 再次解决resolved promise

转载 作者:行者123 更新时间:2023-12-02 04:48:59 24 4
gpt4 key购买 nike

我正在使用 AngularJS 的 $q,当我创建一个 promise 并且该 promise 已经解决时,它可以再次解决吗?我不知道这是否可能,但如果不可能,我是否有办法一次又一次地解决同样的 promise 。我在考虑使用通知方式,但我不知道是否有其他方式可以做到这一点。

最佳答案

来自 Mastering Web Application Development with Angularjs, by Kozlowski and Bacon , 第 3 章“与后端服务器通信”,“使用 $q 的 Promise API”部分:

A promise that was resolved or rejected once can't change its state.

There is only one chance of providing promised results. In other words it is not possible to:

  • Resolve a rejected promise
  • Resolve an already resolved promise with a different result
  • Reject a resolved promise
  • Reject a rejected promise with a different rejection reason

Those rules are rather intuitive.For example, it wouldn't make much sense if we could be called back with the information that there are problems with a pizza order delivery after a pizza was successfully delivered (and probably eaten!).

如果您提供更多代码并且我们可以更好地理解您正在尝试做的事情,我们也许可以为您提供帮助。

关于angularjs - 再次解决resolved promise,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19226147/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com