问题标签 [bluebird]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1922 浏览

javascript - Node Promises Bluebird Collections API 和 Spread() 问题

我正在尝试使用使用 Bluebirds Collection 功能的承诺链。

例如其中一个脚本:

主脚本:

  1. 如何将令牌值传递给每个返回承诺对象的函数?

  2. 如果一个 Promise 对象返回被拒绝,Promise.all() 会发生什么?.all() 是否停止、返回 false 并且未完成数组中的其余项目?

  3. 功能/承诺对象是否并行运行?
  4. 是否可以让 spread() 只接受一个参数并将其应用于返回的每个值?例子: .spread(function(returnedValue) {console.log(JSON.stringify(returnedValue)); });
0 投票
3 回答
2296 浏览

javascript - 如何使用 Bluebird.js nodeify 将第三个参数传递给回调

在一些帮助下,我得到了以下代码来承诺一个 passport.js 登录策略。

通过调用nodeify(done)我可以处理密码匹配的路径,但我不知道如何传递可选的第三个参数,以便 passport.js 可以使用它。

是否可以处理两个失败(不是错误)路径?


更新:

正如评论中所问的那样,我在 Github 上创建了一个问题,并且(非常迅速地)在 Bluebird v2.0 中添加了此功能

https://github.com/petkaantonov/bluebird/issues/219

0 投票
2 回答
9080 浏览

javascript - How do I use Bluebird with Angular?

I tried using Angular with Bluebird promises:

HTML:

JS:

[Fiddle]

However, no matter what I tried, it kept staying "$q promises" and did not update. Except if I added a manual $scope.$apply which I'd rather avoid.

How do I get Bluebird to work with AngularJS?

(I know it's possible since $q does it)

I'm using Bluebird 2.0 which I got here.

0 投票
2 回答
13305 浏览

javascript - Bluebird 承诺 - 如何爆炸数组,然后映射它?

如果我有一个数组:

我怎么能炸开那个数组,给它应用一连串的承诺,然后再把它组合在一起呢?目前我的代码是这样的:

我在想像:

现在,我知道 Bluebird 没有这些功能,所以我想知道正确的 Promise-y 方法是什么?

0 投票
1 回答
687 浏览

node.js - Node.js + Bluebird + csv:额外项目 [object Object]

我有以下用于下载 csv 文件的代码:

当我打开 csv 文件时,第一行右移 1 列:

第一列应该说日期,而不是 [object Object]。我的代码有什么错误?

0 投票
2 回答
5202 浏览

node.js - 在 node.js 中使用 Promise 时是否需要 process.exit(1)

在我们公司,我们正在讨论在使用 Promise 时是否需要在 node.js 中出现未处理的异常时退出进程

两种思想流派一直在我脑海中萦绕

  • 当我们在 node.js 中使用 Promise 时,我们需要使用 process.exit(1)

  • 当我们使用 Promise 时,我们不需要使用 process.exit(1)

顺便说一句,我们计划使用 blubird 模块进行承诺。

https://www.npmjs.org/package/bluebird

我想知道在发生未处理的异常时是否有必要退出进程,因为在使用 Promise 时,我们会得到“finally”语句来清理资源

http://canop.org/blog/?p=516

此外,当涉及到 node.js 时,promise 可能无法自行处理的错误类型(如果有的话)我们可能需要通过

0 投票
1 回答
1036 浏览

javascript - 蓝鸟:取消承诺。加入不会取消孩子

我将 bluebird.js 用于比 jquery 延迟对象更好的承诺对象。我想要做的是并行运行两个请求,当它们都完成时运行一些代码。但我需要能够取消这两个请求。下面是一些突出显示我的问题的示例代码。当我运行它并在加入的承诺上调用取消函数时,我确实抓住了加入但不是在 firstPromise 或 secondPromise 上的取消异常,因此 ajax 请求不会中止。有谁知道如何做到这一点?

0 投票
3 回答
5208 浏览

javascript - Slowdown due to non-parallel awaiting of promises in async generators

I'm writing code using generators and Bluebird and I have the following:

However, this is kind of slow, I feel like my application is waiting too much for I/O and it's not in parallel. How can I improve the performance of my application?

The total response time is 800 for countryFor + 400 for getCommentDataFor + 600 for authenticate so in total 1800ms which is a lot.

0 投票
1 回答
1742 浏览

node.js - Bluebird 承诺和回调,没有错误参数

我正在尝试承诺不使用该callback(err, data)模式的第 3 方库。相反,它们总是返回callback(data)throw出现错误。

用 Promise 包装这样的行为并且仍然让它看起来不错并允许捕获抛出的错误的好方法是什么?catch 子句不会触发,应用程序崩溃。

0 投票
2 回答
9025 浏览

javascript - 如何在没有延迟 anit 模式的情况下将 jQuery $.ajax 调用转换为 Bluebird 承诺

现在我在核心文件中使用 promise.deferred。这使我能够在一个中心位置解决承诺。我一直在阅读我可能正在使用反模式,我想了解它为什么不好。

所以在我的core.js文件中,我有这样的功能:

然后在我的getLocation.js文件中,我有以下内容:

在阅读了 Bluebird 文档和许多关于延迟反模式的博客文章后,我想知道这种模式是否实用。我可以将其更改为以下内容:

核心.js

获取位置.js

我想我对拥有一个使用 jquery 处理 xhr 请求的中央库的最佳方式感到困惑,但 Bluebird 用于承诺。