[Pkg-javascript-commits] [node-bluebird] 07/17: New upstream version 3.5.1+dfsg1
Ross Gammon
ross-guest at moszumanska.debian.org
Tue Oct 10 11:39:57 UTC 2017
This is an automated email from the git hooks/post-receive script.
ross-guest pushed a commit to branch master
in repository node-bluebird.
commit b81b431cbd3d535d013115b2bc6d23f28e8c05ae
Author: Ross Gammon <rosco2 at ubuntu.com>
Date: Sat Oct 7 17:36:05 2017 +0200
New upstream version 3.5.1+dfsg1
---
.travis.yml | 2 +
README.md | 3 +-
bower.json | 2 +-
docs/_config.yml | 2 +-
docs/docs/api-reference.md | 2 +-
docs/docs/api/all.md | 6 +-
docs/docs/api/promise.all.md | 2 +-
docs/docs/api/promise.longstacktraces.md | 2 +-
.../api/promise.onpossiblyunhandledrejection.md | 4 +-
docs/docs/api/promise.setscheduler.md | 2 +-
docs/docs/api/tap.md | 2 +
docs/docs/api/tapcatch.md | 45 +++++++------
docs/docs/changelog.md | 15 +++++
docs/docs/error-explanations.md | 38 +++++------
docs/docs/warning-explanations.md | 16 ++---
docs/docs/why-bluebird.md | 10 +--
docs/docs/working-with-callbacks.md | 74 ++++++----------------
package.json | 2 +-
src/debuggability.js | 5 +-
src/util.js | 5 +-
test/mocha/unhandled_rejections.js | 22 +++++++
tools/README.md | 8 +--
22 files changed, 144 insertions(+), 125 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index b723408..3ac8536 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,6 +7,8 @@ matrix:
- node_js: "4"
- node_js: "5"
- node_js: "6"
+ - node_js: "7"
+ - node_js: "8"
fast_finish: true
env:
- "NODE_FLAGS='' SCRIPT_FLAGS=''"
diff --git a/README.md b/README.md
index b7e02b1..ba82f73 100644
--- a/README.md
+++ b/README.md
@@ -2,8 +2,9 @@
<img src="http://promisesaplus.com/assets/logo-small.png" alt="Promises/A+ logo"
title="Promises/A+ 1.1 compliant" align="right" />
</a>
+
[![Build Status](https://travis-ci.org/petkaantonov/bluebird.svg?branch=master)](https://travis-ci.org/petkaantonov/bluebird)
-[![coverage-98%](http://img.shields.io/badge/coverage-98%-brightgreen.svg?style=flat)](http://petkaantonov.github.io/bluebird/coverage/debug/index.html)
+[![coverage-98%](https://img.shields.io/badge/coverage-98%25-brightgreen.svg?style=flat)](http://petkaantonov.github.io/bluebird/coverage/debug/index.html)
**Got a question?** Join us on [stackoverflow](http://stackoverflow.com/questions/tagged/bluebird), the [mailing list](https://groups.google.com/forum/#!forum/bluebird-js) or chat on [IRC](https://webchat.freenode.net/?channels=#promises)
diff --git a/bower.json b/bower.json
index d996398..ada49d8 100644
--- a/bower.json
+++ b/bower.json
@@ -1,6 +1,6 @@
{
"name": "bluebird",
- "version": "3.5.0",
+ "version": "3.5.1",
"homepage": "https://github.com/petkaantonov/bluebird",
"authors": [
"Petka Antonov <petka_antonov at hotmail.com>"
diff --git a/docs/_config.yml b/docs/_config.yml
index 1bfea4f..ed7eaa5 100644
--- a/docs/_config.yml
+++ b/docs/_config.yml
@@ -19,7 +19,7 @@ markdown: redcarpet
redcarpet:
extensions:
- fenced_code_blocks
-version: 3.5.0
+version: 3.5.1
gems:
- jekyll-redirect-from
destination: ../gh-pages/
diff --git a/docs/docs/api-reference.md b/docs/docs/api-reference.md
index 778ff62..dfc75d4 100644
--- a/docs/docs/api-reference.md
+++ b/docs/docs/api-reference.md
@@ -67,7 +67,7 @@ redirect_from: "/docs/api/index.html"
- [Promise.coroutine.addYieldHandler](api/promise.coroutine.addyieldhandler.html)
- [Utility](api/utility.html)
- [.tap](api/tap.html)
- - [.tapCatch](api/tapCatch.html)
+ - [.tapCatch](api/tapcatch.html)
- [.call](api/call.html)
- [.get](api/get.html)
- [.return](api/return.html)
diff --git a/docs/docs/api/all.md b/docs/docs/api/all.md
index c69fec5..c011c51 100644
--- a/docs/docs/api/all.md
+++ b/docs/docs/api/all.md
@@ -13,7 +13,9 @@ title: .all
.all() -> Promise
```
-Same as [Promise.all(this)](.).
+Consume the resolved [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) and wait for all items to fulfill similar to [Promise.all()](.).
+
+[Promise.resolve(iterable).all()](.) is the same as [Promise.all(iterable)](.).
</markdown></div>
<div id="disqus_thread"></div>
@@ -28,4 +30,4 @@ Same as [Promise.all(this)](.).
(document.getElementsByTagName("head")[0] || document.getElementsByTagName("body")[0]).appendChild(dsq);
})();
</script>
-<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript>
\ No newline at end of file
+<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript>
diff --git a/docs/docs/api/promise.all.md b/docs/docs/api/promise.all.md
index fd3703f..07bfdf1 100644
--- a/docs/docs/api/promise.all.md
+++ b/docs/docs/api/promise.all.md
@@ -10,7 +10,7 @@ title: Promise.all
##Promise.all
```js
-Promise.all(Iterable<any>|Promise<Iterable<any>> input) -> Promise
+Promise.all(Iterable<any>|Promise<Iterable<any>> input) -> Promise<Array<any>>
```
This method is useful for when you want to wait for more than one promise to complete.
diff --git a/docs/docs/api/promise.longstacktraces.md b/docs/docs/api/promise.longstacktraces.md
index d8d45a8..4bbc380 100644
--- a/docs/docs/api/promise.longstacktraces.md
+++ b/docs/docs/api/promise.longstacktraces.md
@@ -23,7 +23,7 @@ Promise.config({
Promise.longStackTraces() -> undefined
```
-Call this right after the library is loaded to enable long stack traces. Long stack traces cannot be disabled after being enabled, and cannot be enabled after promises have alread been created. Long stack traces imply a substantial performance penalty, around 4-5x for throughput and 0.5x for latency.
+Call this right after the library is loaded to enable long stack traces. Long stack traces cannot be disabled after being enabled, and cannot be enabled after promises have already been created. Long stack traces imply a substantial performance penalty, around 4-5x for throughput and 0.5x for latency.
Long stack traces are enabled by default in the debug build.
diff --git a/docs/docs/api/promise.onpossiblyunhandledrejection.md b/docs/docs/api/promise.onpossiblyunhandledrejection.md
index 61817db..666d78a 100644
--- a/docs/docs/api/promise.onpossiblyunhandledrejection.md
+++ b/docs/docs/api/promise.onpossiblyunhandledrejection.md
@@ -14,7 +14,7 @@ Promise.onPossiblyUnhandledRejection(function(any error, Promise promise) handle
```
-*Note: this hook is specific to the bluebird instance its called on, application developers should use [global rejection events](/docs/api/error-management-configuration.html#global-rejection-events)*
+*Note: this hook is specific to the bluebird instance it's called on, application developers should use [global rejection events](/docs/api/error-management-configuration.html#global-rejection-events)*
Add `handler` as the handler to call when there is a possibly unhandled rejection. The default handler logs the error stack to stderr or `console.error` in browsers.
@@ -39,4 +39,4 @@ Passing no value or a non-function will have the effect of removing any kind of
(document.getElementsByTagName("head")[0] || document.getElementsByTagName("body")[0]).appendChild(dsq);
})();
</script>
-<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript>
\ No newline at end of file
+<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript>
diff --git a/docs/docs/api/promise.setscheduler.md b/docs/docs/api/promise.setscheduler.md
index fcc1284..23f8ef3 100644
--- a/docs/docs/api/promise.setscheduler.md
+++ b/docs/docs/api/promise.setscheduler.md
@@ -35,7 +35,7 @@ Promise.setScheduler(function(fn) {
});
```
-> **Danger** - in order to keep bluebird promises [Promises/A+](http://www.promisesaplus) compliant a scheduler that executes the function asynchronously (like the examples in this page) must be used.
+> **Danger** - in order to keep bluebird promises [Promises/A+](https://promisesaplus.com/) compliant a scheduler that executes the function asynchronously (like the examples in this page) must be used.
</markdown></div>
diff --git a/docs/docs/api/tap.md b/docs/docs/api/tap.md
index 489cc4b..5d17248 100644
--- a/docs/docs/api/tap.md
+++ b/docs/docs/api/tap.md
@@ -12,7 +12,9 @@ title: .tap
```js
.tap(function(any value) handler) -> Promise
```
+Essentially like `.then()`, except that the value passed in is the value returned.
+This means you can insert `.tap()` into a `.then()` chain without affecting what is passed through the chain. (See example below).
Unlike [`.finally`](.) this is not called for rejections.
diff --git a/docs/docs/api/tapcatch.md b/docs/docs/api/tapcatch.md
index 079d302..d5a39a6 100644
--- a/docs/docs/api/tapcatch.md
+++ b/docs/docs/api/tapcatch.md
@@ -13,8 +13,8 @@ title: .tapCatch
`.tapCatch` is a convenience method for reacting to errors without handling them with promises - similar to `finally` but only called on rejections. Useful for logging errors.
It comes in two variants.
- - A tapCatch-all variant similar to [`.catch`](.) block. This variant is compatible with native promises.
- - A filtered variant (like other non-JS languages typically have) that lets you only handle specific errors. **This variant is usually preferable**.
+- A tapCatch-all variant similar to [`.catch`](.) block. This variant is compatible with native promises.
+- A filtered variant (like other non-JS languages typically have) that lets you only handle specific errors. **This variant is usually preferable**.
### `tapCatch` all
@@ -35,8 +35,9 @@ getUser().tapCatch(function(err) {
Common case includes adding logging to an existing promise chain:
-**Rate Limiting**
-```
+#### Rate Limiting
+
+```js
Promise.
try(logIn).
then(respondWithSuccess).
@@ -44,8 +45,9 @@ Promise.
catch(respondWithError);
```
-**Circuit Breakers**
-```
+#### Circuit Breakers
+
+```js
Promise.
try(makeRequest).
then(respondWithSuccess).
@@ -53,14 +55,16 @@ Promise.
catch(respondWithError);
```
-**Logging**
-```
+#### Logging
+
+```js
Promise.
try(doAThing).
tapCatch(logErrorsRelatedToThatThing).
then(respondWithSuccess).
catch(respondWithError);
```
+
*Note: in browsers it is necessary to call `.tapCatch` with `console.log.bind(console)` because console methods can not be called as stand-alone functions.*
### Filtered `tapCatch`
@@ -84,27 +88,30 @@ This is an extension to [`.tapCatch`](.) to filter exceptions similarly to langu
Usage examples include:
-**Rate Limiting**
-```
-Bluebird.
+#### Rate Limiting
+
+```js
+Promise.
try(logIn).
then(respondWithSuccess).
tapCatch(InvalidCredentialsError, countFailuresForRateLimitingPurposes).
catch(respondWithError);
```
-**Circuit Breakers**
-```
-Bluebird.
+#### Circuit Breakers
+
+```js
+Promise.
try(makeRequest).
then(respondWithSuccess).
tapCatch(RequestError, adjustCircuitBreakerState).
catch(respondWithError);
```
-**Logging**
-```
-Bluebird.
+#### Logging
+
+```js
+Promise.
try(doAThing).
tapCatch(logErrorsRelatedToThatThing).
then(respondWithSuccess).
@@ -115,9 +122,9 @@ Bluebird.
<div id="disqus_thread"></div>
<script type="text/javascript">
- var disqus_title = ".tap";
+ var disqus_title = ".tapCatch";
var disqus_shortname = "bluebirdjs";
- var disqus_identifier = "disqus-id-tap";
+ var disqus_identifier = "disqus-id-tapCatch";
(function() {
var dsq = document.createElement("script"); dsq.type = "text/javascript"; dsq.async = true;
diff --git a/docs/docs/changelog.md b/docs/docs/changelog.md
index b4c0f64..5c802e0 100644
--- a/docs/docs/changelog.md
+++ b/docs/docs/changelog.md
@@ -3,6 +3,21 @@ id: changelog
title: Changelog
---
+## 3.5.0 (2017-03-03)
+
+Features:
+
+ - Added new method: [.tapCatch](.) \([#1220](.)\)
+
+Bugfixes:
+
+ - Fixed streamline benchmarks \([#1233](.)\)
+ - Fixed yielding a function calling the function \([#1314](.), [#1315](.)\)
+ - Fixed confusing error message when calling [.catch](.) with non function predicate \([#1350](.)\)
+ - Fixed [.props](.) resolving to empty object when called with empty `Map` \([#1338](.)\)
+ - Fixed confusing error message when invoking `Promise` directly without `new` \([#1320](.)\)
+ - Added dedicated webpack entry point \([#1318](.)\)
+
## 3.4.7 (2016-12-22)
- Promise config returns reference to Bluebird library
diff --git a/docs/docs/error-explanations.md b/docs/docs/error-explanations.md
index 7dd9d24..8238823 100644
--- a/docs/docs/error-explanations.md
+++ b/docs/docs/error-explanations.md
@@ -23,7 +23,7 @@ title: Error Explanations
- [Error: No async scheduler available](#error-no-async-scheduler-available)
-##Error: Promise.promisify called on an object
+## Error: Promise.promisify called on an object
You got this this error because you've used `Promise.promisify` on an object, for example:
@@ -38,7 +38,7 @@ Instead, use [`Promise.promisifyAll`](.) :
var fs = Promise.promisifyAll(require("fs"));
```
-##Error: the promise constructor requires a resolver function
+## Error: the promise constructor requires a resolver function
You got this error because you used `new Promise()` or `new Promise(something)` without passing a function as the parameter.
@@ -57,11 +57,11 @@ function wrapWithPromise(parameter) {
Please consider reading about [new Promise](.) and also consider checking out automatic [promisification](.) as well as [Promise.method](.)
-##Error: the promise constructor cannot be invoked directly
+## Error: the promise constructor cannot be invoked directly
You can get this error for several reasons:
-####1. You forgot to use `new` when creating a new promise using `new Promise(resolver)` syntax.
+#### 1. You forgot to use `new` when creating a new promise using `new Promise(resolver)` syntax.
This can happen when you tried to do something like:
@@ -77,11 +77,11 @@ You can correct this by doing:
Please consider reading about [new Promise](.) and also consider checking out automatic [promisification](.) as well as [Promise.method](.)
-####2. You are trying to subclass `Promise`
+#### 2. You are trying to subclass `Promise`
Bluebird does not support extending promises this way. Instead, see [scoped prototypes](features.html#scoped-prototypes).
-##Error: expecting an array, a promise or a thenable
+## Error: expecting an array, a promise or a thenable
The function being called expects a Promise, but is given something different. There are two main reasons why this may occur.
@@ -148,7 +148,7 @@ myFunction().then(result => {
```
-##Error: generatorFunction must be a function
+## Error: generatorFunction must be a function
You are getting this error when trying to use [Promise.coroutine](.) and not passing it a generator function as a parameter. For example:
@@ -170,11 +170,11 @@ Please refer to the relevant section in the documentation about [Generators](.)
[Promise.coroutine](.) is built to work with generators to form C# like `async/await`
-##Error: fn must be a function
+## Error: fn must be a function
You passed a non-function where a function was expected.
-##Error: cannot enable long stack traces after promises have been created
+## Error: cannot enable long stack traces after promises have been created
You are getting this error because you are enabling long stack traces after a promise has already been created.
@@ -188,7 +188,7 @@ Promise.config({
See the API page about [Promise.longStackTraces](.)
-##Error: cannot get fulfillment value of a non-fulfilled promise
+## Error: cannot get fulfillment value of a non-fulfilled promise
You can get this error when you're trying to call `.value` or `.error` when inspecting a promise where the promise has not been fulfilled or rejected yet.
@@ -203,7 +203,7 @@ Consider using [.isPending()](.) [.isFulfilled()](.) and [.isRejected()](.) in o
Please consider reading more about [synchronous inspection](.)
-##Error: cannot get rejection reason of a non-rejected promise
+## Error: cannot get rejection reason of a non-rejected promise
You can get this error when you're trying to call `.value` or `.error` when inspecting a promise where the promise has not been fulfilled or rejected yet.
@@ -227,7 +227,7 @@ In general, the usage of [Promise.promisifyAll](.) is along the lines of `var fs
Consider reading the section about [promisification](.)
-##Error: circular promise resolution chain
+## Error: circular promise resolution chain
This usually happens when you have a promise that resolves or rejects with itself.
@@ -241,7 +241,7 @@ Promises do not aim to solve such live updating problems directly. One option wo
resolving it with itself tells it "it is done when it is done"
-##Error: cannot await properties of a non-object
+## Error: cannot await properties of a non-object
The `.props` method expects to receive an object.
@@ -259,7 +259,7 @@ Promise.props({
This happens when a non object value or a promise that resolves with something that is not an object is being passed instead.
-##Error: expecting a positive integer
+## Error: expecting a positive integer
This happens when you call `.some` passing it a negative value or a non-integer.
@@ -267,7 +267,7 @@ One possible cause is using `.indexOf` which returns `-1` when it doesn't find t
Please consider reading the API docs for [`.some`](.)
-##Error: A value was yielded that could not be treated as a promise
+## Error: A value was yielded that could not be treated as a promise
You are getting this error because you have tried to `yield` something in a coroutine without a yield handler, for example:
@@ -289,7 +289,7 @@ var coroutine = Promise.coroutine(function*(){
Or to use [Promise.coroutine.addYieldHandler`](.) to teach [Promise.coroutine](.) to accept these sort of values.
-##Error: cannot await properties of a non object
+## Error: cannot await properties of a non object
The `.props` method expects to receive an object.
@@ -308,7 +308,7 @@ Promise.props({
This happens when a non object value or a promise that resolves with something that is not an object is being passed instead.
-##Error: Cannot promisify an API that has normal methods
+## Error: Cannot promisify an API that has normal methods
This error indicates you have tried to call [Promise.promisifyAll](.) on an object that already has a property with the `Async` suffix:
@@ -322,7 +322,7 @@ You may also use the custom suffix option to choose another suffix that doesn't
If you find this issue in a common library please [open an issue](https://github.com/petkaantonov/bluebird/issues/new).
-##Error: Catch filter must inherit from Error or be a simple predicate function
+## Error: Catch filter must inherit from Error or be a simple predicate function
Bluebird supports typed and predicate [.catch()](.) calls]. However in order to use the typed/predicate catch syntax for error handling you must do one of two things.
@@ -340,7 +340,7 @@ Alternatively, if you provide it a predicate be sure it's a simple function:
Please see the API docs of [.catch()](.) on how to use predicate catches.
-##Error: No async scheduler available
+## Error: No async scheduler available
Async scheduler is a function that takes a callback function and calls the callback function as soon as possible, but asynchronously. For example `setTimeout`.
diff --git a/docs/docs/warning-explanations.md b/docs/docs/warning-explanations.md
index dcf9055..2d892f8 100644
--- a/docs/docs/warning-explanations.md
+++ b/docs/docs/warning-explanations.md
@@ -5,13 +5,13 @@ title: Warning Explanations
[warning-explanations](unfinished-article)
- - [Warning: .then() only accepts functions](#warning-.then)
+ - [Warning: .then() only accepts functions](#warning-then-only-accepts-functions)
- [Warning: a promise was rejected with a non-error](#warning-a-promise-was-rejected-with-a-non-error)
- [Warning: a promise was created in a handler but was not returned from it](#warning-a-promise-was-created-in-a-handler-but-was-not-returned-from-it)
Note - in order to get full stack traces with warnings in Node 6.x+ you need to enable to `--trace-warnings` flag which will give you a full stack trace of where the warning is coming from.
-##Warning: .then() only accepts functions
+## Warning: .then() only accepts functions
If you see this warning your code is probably not doing what you expect it to, the most common reason is passing the *result* of calling a function to [.then()](.) instead of the function *itself*:
@@ -33,20 +33,20 @@ getImage().then(processImage)
*If you are wondering why this is a warning and not a simple TypeError it is because the due to historic reasons Promises/A+ specification requires that incorrect usage is silently ignored.*
-##Warning: a promise was rejected with a non-error
+## Warning: a promise was rejected with a non-error
Due to a historic mistake in JavaScript, the `throw` statement is allowed to be used with any value, not just errors, and Promises/A+ choosing to inherit this mistake, it is possible to reject a promise with a value that is not an error.
-An error is an object that is a `instanceof Error`. It will at minimum have the properties `.stack` and `.message`, which are an absolute must to have for any value that is being used in an automatic propagation mechanism such as exceptions and rejections. This is because errors are usually handled many levels above from where they actually originated from - the error object must have sufficient metadata about it so that its ultimate handler many levels above will have all the informatio [...]
+An error is an object that is a `instanceof Error`. It will at minimum have the properties `.stack` and `.message`, which are an absolute *must* have for any value that is being used in an automatic propagation mechanism, such as exceptions and rejections. This is because errors are usually handled many levels above where they actually originate - the error object must have sufficient metadata about it so that its ultimate handler (possibly many levels above) will have all the informatio [...]
-Since all objects support having properties you might still wonder why exactly does it have to be an error object and not just any object. In addition to supporting properties, an equally important feature necessary for values that are automatically propagated is the stack trace property (`.stack`). A stack trace allows you easily find where an error originated from.
+Since all objects support having properties you might still wonder why exactly does it have to be an error object and not just any object. In addition to supporting properties, an equally important feature necessary for values that are automatically propagated is the stack trace property (`.stack`). A stack trace allows you easily find where an error originated from as it gives the code's call stack - along with line numbers for reference in code files.
-You should heed this warning because rejecting a promise with a non-error makes debugging extremely hard and costly. Additionally, if you reject with simple primitives such as `undefined` (commonly caused by simple calling `reject()`) you cannot handle errors at all because it's impossible to tell from `undefined` what exactly went wrong. All you can tell the user is that "something went wrong" and lose them forever.
+You should heed this warning because rejecting a promise with a non-error makes debugging extremely hard and costly. Additionally, if you reject with simple primitives such as `undefined` (commonly caused by simply calling `reject()`) you cannot handle errors at all because it's impossible to tell from `undefined` what exactly went wrong. All you can tell the user is that "something went wrong" and lose them forever.
-##Warning: a promise was created in a handler but was not returned from it
+## Warning: a promise was created in a handler but was not returned from it
-This usually means that you simply forgot a `return` statement somewhere which will cause a runaway promise that is not connected to any promise chain.
+This usually means that you simply forgot a `return` statement somewhere, which will cause a runaway promise that is not connected to any promise chain.
For example:
diff --git a/docs/docs/why-bluebird.md b/docs/docs/why-bluebird.md
index 3fea3dd..e136af4 100644
--- a/docs/docs/why-bluebird.md
+++ b/docs/docs/why-bluebird.md
@@ -3,20 +3,20 @@ id: why-bluebird
title: Why bluebird?
---
-There are many third party promise libraries available for JavaScript and even the standard library contains a promise implementation in newer versions of browsers and node/io.js. This page will explore why one might use bluebird promises over other third party or the standard library implementations. For reasons why to use promises in general, see the [Why Promises?](why-promises.html) article.
+There are many third party promise libraries available for JavaScript and even the standard library contains a promise implementation in newer versions of browsers and node/io.js. This page will explore why one might use bluebird promises over other third party or the standard library implementations. For reasons to use promises in general, see the [Why Promises?](why-promises.html) article.
###Bluebird design principles
Bluebird is built with the following design principles in mind:
- **Pragmatic and not theoretical.** - Bluebird will always pick the pragmatic route vs the theoretically elegant one when there is a conflict. The library's API was created based on real-life use cases and after a lot of consideration.
- - **Fully featured without bloat** - Bluebird provides all the tools and utilities needed to realize a highly expressive and fluent DSL for asynchronous JavaScript without suffering from bloat by avoiding incorporating features that are solely motivated by theoretical arguments, have extremely narrow applicability or have limited synergy and composability with existing features.
- - **Easy to debug** - A major consequence of choosing pragmatism over theoretical elegancy, a property that among promise libraries taken to this extent is unique to bluebird.
+ - **Fully featured without bloat** - Bluebird provides all the tools and utilities needed to realize a highly expressive and fluent DSL for asynchronous JavaScript without suffering from bloat by avoiding incorporating features that are solely motivated by theoretical arguments, have extremely narrow applicability, or have limited synergy and composability with existing features.
+ - **Easy to debug** - A major consequence of choosing pragmatism over theoretical elegance, a property that is unique to bluebird among promise libraries taken to this extent.
- Bluebird ships with the best cross-platform long stack traces out there and a warning system. This helps you recognize common and devastating promise usage mistakes early before they lead to hard to debug code later.
- Unhandled errors are not silently swallowed by default but reported along with helpful stack traces where applicable. All of this is of course configurable.
- - **Zero overhead abstraction** - In server-side applications the performance of a promise implementation matters. Bluebird's server side performance is measured with highly relevant realistic end-to-end macro [benchmarks](benchmarks.html) and consistently comes out on top. We understand that if bluebird is as close to a zero cost abstraction as possible, developers won't be tempted to short-circuit and absorb complexity themselves.
+ - **Zero overhead abstraction** - In server-side applications the performance of a promise implementation matters. Bluebird's server-side performance is measured with highly relevant and realistic end-to-end macro [benchmarks](benchmarks.html), and consistently comes out on top. We understand that if bluebird is as close to a zero cost abstraction as possible, developers won't be tempted to short-circuit and absorb complexity themselves.
- **Runs everywhere** - Bluebird runs on pretty much every platform. This makes bluebird ideal for projects who care about providing consistent cross-platform and cross-version experience. It runs on old IE, it has even been known to run on Netscape 7.
- - **Spec compatible** - bluebird can work as a drop-in replacement for native promises for an instant performance boost. It passes the Promises/A+ test suite and is fully spec compliant.
+ - **Spec compatible** - Bluebird can work as a drop-in replacement for native promises for an instant performance boost. It passes the Promises/A+ test suite and is fully spec compliant.
diff --git a/docs/docs/working-with-callbacks.md b/docs/docs/working-with-callbacks.md
index a420826..65fe399 100644
--- a/docs/docs/working-with-callbacks.md
+++ b/docs/docs/working-with-callbacks.md
@@ -232,47 +232,30 @@ using(getSqlConnection(), function(conn) {
});
```
-It's also possible to use disposers for transaction management:
-
-```js
-var pg = require('pg');
-// uncomment if necessary
-//var Promise = require("bluebird");
-//Promise.promisifyAll(pg, {
-// filter: function(methodName) {
-// return methodName === "connect"
-// },
-// multiArgs: true
-//});
-// Promisify rest of pg normally
-//Promise.promisifyAll(pg);
-
-function getTransaction(connectionString) {
- var close;
- return pg.connectAsync(connectionString).spread(function(client, done) {
- close = done;
- return client.queryAsync('BEGIN').then(function () {
- return client;
- });
- }).disposer(function(client, promise) {
- if (promise.isFulfilled()) {
- return client.queryAsync('COMMIT').then(closeClient);
- } else {
- return client.queryAsync('ROLLBACK').then(closeClient);
- }
- function closeClient() {
- if (close) close(client);
- }
- });
+It's also possible to use a disposer pattern (but not actual disposers) for transaction management:
+
+```js
+
+function withTransaction(fn) {
+ return Promise.using(pool.acquireConnection(), function(connection) {
+ var tx = connection.beginTransaction()
+ return Promise
+ .try(fn, tx)
+ .then(function(res) { return connection.commit().thenReturn(res) },
+ function(err) {
+ return connection.rollback()
+ .catch(function(e) {/* maybe add the rollback error to err */})
+ .thenThrow(err);
+ });
+ });
}
-
-exports.getTransaction = getTransaction;
+exports.withTransaction = withTransaction;
```
Which would let you do:
```js
-using(getTransaction(), function(tx) {
+withTransaction(tx => {
return tx.queryAsync(...).then(function() {
return tx.queryAsync(...)
}).then(function() {
@@ -308,26 +291,7 @@ function getSqlConnection() {
module.exports = getSqlConnection;
```
-The usage pattern is similar to the PostgreSQL example above. You can also create a disposer for transactions and use it safely:
-
-```js
-function getTransaction() {
- return db.getTransactionAsync().disposer(function(tx, promise) {
- return promise.isFulfilled() ? tx.commitAsync() : tx.rollbackAsync();
- });
-}
-
-
-// If the using block completes successfully, the transaction is automatically committed
-// Any error or rejection will automatically roll it back
-using(getTransaction(), function(tx) {
- return tx.queryAsync(...).then(function() {
- return tx.queryAsync(...)
- }).then(function() {
- return tx.queryAsync(...)
- });
-});
-```
+The usage pattern is similar to the PostgreSQL example above. You can also use a disposer pattern (but not an actual .disposer). See the PostgreSQL example above for instructions.
###More common examples
diff --git a/package.json b/package.json
index 721821e..8e4d073 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "bluebird",
"description": "Full featured Promises/A+ implementation with exceptionally good performance",
- "version": "3.5.0",
+ "version": "3.5.1",
"keywords": [
"promise",
"performance",
diff --git a/src/debuggability.js b/src/debuggability.js
index 6591449..8a97eab 100644
--- a/src/debuggability.js
+++ b/src/debuggability.js
@@ -39,7 +39,10 @@ Promise.prototype.suppressUnhandledRejections = function() {
Promise.prototype._ensurePossibleRejectionHandled = function () {
if ((this._bitField & IS_REJECTION_IGNORED) !== 0) return;
this._setRejectionIsUnhandled();
- async.invokeLater(this._notifyUnhandledRejection, this, undefined);
+ var self = this;
+ setTimeout(function() {
+ self._notifyUnhandledRejection();
+ }, 1);
};
Promise.prototype._notifyUnhandledRejectionIsHandled = function () {
diff --git a/src/util.js b/src/util.js
index d81a9fc..1729b78 100644
--- a/src/util.js
+++ b/src/util.js
@@ -234,10 +234,11 @@ function safeToString(obj) {
}
function isError(obj) {
- return obj !== null &&
+ return obj instanceof Error ||
+ (obj !== null &&
typeof obj === "object" &&
typeof obj.message === "string" &&
- typeof obj.name === "string";
+ typeof obj.name === "string");
}
function markAsOriginatingFromRejection(e) {
diff --git a/test/mocha/unhandled_rejections.js b/test/mocha/unhandled_rejections.js
index 46f19f4..cf36add 100644
--- a/test/mocha/unhandled_rejections.js
+++ b/test/mocha/unhandled_rejections.js
@@ -752,3 +752,25 @@ describe("Unhandled rejection when joining chains with common rejected parent",
return Promise.all([test1, test2]);
});
});
+
+var asyncAwaitSupported = (function() {
+ try {
+ new Function("async function abc() {}");
+ return true;
+ } catch (e) {
+ return false;
+ }
+})();
+
+if (asyncAwaitSupported) {
+ describe("No unhandled rejection from async await", function () {
+ setupCleanUps();
+ specify("gh-1404", function testFunction() {
+ var ret = onUnhandledFail(testFunction);
+ Promise.using(Promise.resolve(),
+ (new Function("Bluebird", "return async function() { await Bluebird.reject(new Error('foo')); }"))(Promise))
+ .caught(function() {});
+ return ret;
+ });
+ });
+}
diff --git a/tools/README.md b/tools/README.md
index 996df74..e210e89 100644
--- a/tools/README.md
+++ b/tools/README.md
@@ -1,16 +1,16 @@
-##Tools
+## Tools
Tools that can be run from command line:
-###test.js
+### test.js
For running tests. See [Testing](../#testing).
-###build.js
+### build.js
For building the library. See [Custom builds](../#custom-builds).
-###jshintrc_generator.js
+### jshintrc_generator.js
Generates a .jshintrc file in the project root.
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-bluebird.git
More information about the Pkg-javascript-commits
mailing list