I have some old JavaScript libraries that use jQuery promises as return objects from function calls. I'm now using AngularJS which uses the $q service (inspired by the Q library). Does anybody have some generic JavaScript code to make these two different promise implementations compatible, so that jQuery promises can be used as if it where $q promises? Or something similar?
我有一些旧的JavaScript库,它们使用jQuery promises作为函数调用的返回对象。我现在正在使用AngularJS,它使用$ q服务(灵感来自Q库)。有没有人有一些通用的JavaScript代码来使这两个不同的promise实现兼容,所以jQuery promise可以像$ q promises一样使用?或类似的东西?
1 个解决方案
#1
21
Third party promises can be wrapped with $q.when(thirdPartyPromise)
to be converted into $q promises. When the thirdPartyPromise
resolves, the $q promise resolves accordingly and $scope.$apply()
is called.
第三方承诺可以用$ q.when(thirdPartyPromise)包装转换为$ q promises。当thirdPartyPromise解析时,$ q promise会相应地解析$ scope。$ apply()被调用。
#1
21
Third party promises can be wrapped with $q.when(thirdPartyPromise)
to be converted into $q promises. When the thirdPartyPromise
resolves, the $q promise resolves accordingly and $scope.$apply()
is called.
第三方承诺可以用$ q.when(thirdPartyPromise)包装转换为$ q promises。当thirdPartyPromise解析时,$ q promise会相应地解析$ scope。$ apply()被调用。