gpt4 book ai didi

javascript - 让 Promise 等待回调

转载 作者:行者123 更新时间:2023-11-28 06:25:22 25 4
gpt4 key购买 nike

我正在为一个始终使用 Promises 的框架编写一个插件。该插件预计会返回一个 Promise 来处理该事件,并且该插件在处理期间执行的任何操作都会在返回下一个事件之前链接起来。我认为...

无论如何 - 我还使用一个完全基于回调的旧库 - 并且回调不遵循将回调(err,resp)作为最后一个参数的标准约定。

我该如何转动它:

var call = libary.Api(_this.config.url, function(response){return new Promise() {Do my actions with the response..}}, _this.config.api_key);

return BbPromise.try(call).then(evt);

进入依赖于正在处理的回调的 Promise?

最佳答案

试试这个:

return (new BbPromise(function(resolve) {
libary.Api(_this.config.url, function(response) {
resolve(response);
}, _this.config.api_key);
})).then(evt);

关于javascript - 让 Promise 等待回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35174138/

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