+4
-0
@@ -0,1 +1,5 @@ | ||
| # prfun 1.0.2 (2014-11-06) | ||
| * Fix potential resource leak in `Promise#timeout`. | ||
| # prfun 1.0.1 (2014-09-25) | ||
@@ -2,0 +6,0 @@ |
+8
-1
@@ -292,2 +292,8 @@ // Utility functions for ES6 Promises. | ||
| var makeRejector = function(reject, message, ms) { | ||
| // create this function in an outer scope so that we don't inadvertently | ||
| // keep a reference to the promise here. Perhaps this is overkill. | ||
| var id = setTimeout(function() { reject(new TimeoutError(message)); }, ms); | ||
| return function() { clearTimeout(id); }; | ||
| }; | ||
| Promise.prototype.timeout = function(ms, message) { | ||
@@ -298,3 +304,4 @@ var P = this.constructor || Promise; | ||
| promise.then(resolve, reject); | ||
| setTimeout(function() { reject(new TimeoutError(message)); }, ms); | ||
| var cleanup = makeRejector(reject, message, ms); | ||
| promise.then(cleanup, cleanup); | ||
| }); | ||
@@ -301,0 +308,0 @@ }; |
+1
-1
| { | ||
| "name": "prfun", | ||
| "version": "1.0.1", | ||
| "version": "1.0.2", | ||
| "description": "Helper functions for ES6 promises", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
+18
-1
@@ -945,4 +945,21 @@ # prfun | ||
| `Promise#finally` works like [Q's finally method](https://github.com/kriskowal/q/wiki/API-Reference#wiki-promisefinallycallback). | ||
| `Promise#finally` works like [Q's finally method](https://github.com/kriskowal/q/wiki/API-Reference#wiki-promisefinallycallback), unless `callback` returns a rejected promise. | ||
| Note that the parallel with synchronous `finally` is not exact: | ||
| ```js | ||
| // as expected: | ||
| (function() { try { return 1; } finally { throw "2"; } })(); // throws "2" | ||
| Promise.resolve(1).finally(function() { throw "2"; }); // rejects with "2" | ||
| // but: | ||
| (function() { try { return 1; } finally { return 2; } })(); // returns 2 | ||
| Promise.resolve(1).finally(function() { return 2; }); // resolves to '1' | ||
| // compare: | ||
| (function() { try { return 1; } finally { 2; } })(); // returns 1 | ||
| ``` | ||
| This asymmetry is because the `Promise` API can't distinguish the `return` | ||
| statement from an expression evaluating to a value. | ||
| <hr> | ||
@@ -949,0 +966,0 @@ |
191593
0.57%4485
0.16%1434
1.2%