将承诺转换为蓝鸟 [英] Convert promise to bluebird
问题描述
我找到了一个使用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屋!