将承诺转换为蓝鸟 [英] Convert promise to bluebird

查看:156
本文介绍了将承诺转换为蓝鸟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了一个使用promises的现有库,但是它没有使用bluebird。库函数没有附带bluebird所有的额外功能 .map() .tap() 。我如何将正常或非蓝鸟承诺转换为蓝鸟承诺,蓝鸟提供的所有额外功能?

I found an existing library that uses promises, however it doesn't use bluebird. The library functions don't come with all the extra features bluebird does like .map() or .tap(). How do I convert a "normal" or "non-bluebird" promise to a bluebird one, with all the extra features bluebird offers?

我尝试将现有的承诺包含在 Promise.promisify Promise.resolve ,似乎都不起作用。

I tried wrapping the existing promise in Promise.promisify and Promise.resolve and neither seemed to work.

推荐答案

使用 Promise.resolve - 它将采取任何可能的,例如来自其他实现的承诺,并将其同化为Bluebird承诺。

Use Promise.resolve - it will take any thenable, like a promise from some other implementation, and assimilate it into a Bluebird promise.

请注意,解决一词可能会产生误导,并不意味着与履行相同,但也可以遵循另一个承诺并接受其结果。

Keep in mind that the term "resolve" can be misleading, it does not mean the same as "fulfill" but can also follow another promise and settle to its result.

这篇关于将承诺转换为蓝鸟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆