Comparing version 0.9.8-0 to 0.9.9-0
43
API.md
@@ -36,2 +36,3 @@ #API Reference | ||
- [`.any()`](#any---promise) | ||
- [`.race()`](#race---promise) | ||
- [`.some(int count)`](#someint-count---promise) | ||
@@ -46,2 +47,3 @@ - [`.spread([Function fulfilledHandler] [, Function rejectedHandler ])`](#spreadfunction-fulfilledhandler--function-rejectedhandler----promise) | ||
- [`Promise.any(Array<dynamic>|Promise values)`](#promiseanyarraydynamicpromise-values---promise) | ||
- [`Promise.race(Array|Promise promises)`](#promiseracearraypromise-promises---promise) | ||
- [`Promise.some(Array<dynamic>|Promise values, int count)`](#promisesomearraydynamicpromise-values-int-count---promise) | ||
@@ -846,2 +848,9 @@ - [`Promise.join([dynamic value...])`](#promisejoindynamic-value---promise) | ||
#####`.race()` -> `Promise` | ||
Same as calling [Promise.race\(thisPromise\)](#promiseracearraypromise-promises---promise). With the exception that if this promise is [bound](#binddynamic-thisarg---promise) to a value, the returned promise is bound to that value too. | ||
<hr> | ||
#####`.some(int count)` -> `Promise` | ||
@@ -991,2 +1000,36 @@ | ||
#####`Promise.race(Array|Promise promises)` -> `Promise` | ||
Given an array, or a promise of an array, which contains promises (or a mix of promises and values) return a promise that is fulfilled or rejected as soon as a promise in the array is fulfilled or rejected with the respective rejection reason or fulfillment value. | ||
Example of implementing a timeout in terms of `Promise.race`: | ||
```js | ||
var Promise = require("bluebird"); | ||
var fs = Promise.promisifyAll(require("fs")); | ||
function delay(ms) { | ||
return new Promise(function (v) { | ||
setTimeout(v, ms); | ||
}); | ||
} | ||
function timeout(promise, time) { | ||
var timeout = delay(time).then(function () { | ||
throw new Promise.TimeoutError("Operation timed out after " + time + " ms"); | ||
}); | ||
return Promise.race([promise, timeout]); | ||
} | ||
timeout(fs.readFileAsync("slowfile.txt"), 300).then(function (contents) { | ||
console.log("Here are the contents", contents); | ||
}). | ||
catch(Promise.TimeoutError, function (e) { | ||
console.error("Sorry retrieving file took too long"); | ||
}); | ||
``` | ||
<hr> | ||
#####`Promise.some(Array<dynamic>|Promise values, int count)` -> `Promise` | ||
@@ -993,0 +1036,0 @@ |
@@ -0,1 +1,34 @@ | ||
## 0.9.8-0 (2013-11-01) | ||
Bugfixes: | ||
- Fix bug with `Promise.try` not unwrapping returned promises and thenables | ||
## 0.9.7-0 (2013-10-29) | ||
Bugfixes: | ||
- Fix bug with build files containing duplicated code for promise.js | ||
## 0.9.6-0 (2013-10-28) | ||
Features: | ||
- Improve output of reporting unhandled non-errors | ||
- Implement RejectionError wrapping and `.error()` method | ||
## 0.9.5-0 (2013-10-27) | ||
Features: | ||
- Allow fresh copies of the library to be made | ||
## 0.9.4-1 (2013-10-27) | ||
## 0.9.4-0 (2013-10-27) | ||
Bugfixes: | ||
- Rollback non-working multiple fresh copies feature | ||
## 0.9.3-0 (2013-10-27) | ||
@@ -2,0 +35,0 @@ |
@@ -9,5 +9,7 @@ "use strict"; | ||
module.exports = function( grunt ) { | ||
var isCI = !!grunt.option("ci"); | ||
var optionalModuleDependencyMap = { | ||
"any.js": ['Promise', 'Promise$_All', 'PromiseArray'], | ||
"race.js": ['Promise', 'Promise$_All', 'PromiseArray'], | ||
"call_get.js": ['Promise'], | ||
@@ -32,2 +34,3 @@ "filter.js": ['Promise', 'Promise$_All', 'PromiseArray', 'apiRejection'], | ||
var optionalModuleRequireMap = { | ||
"race.js": true, | ||
"any.js": true, | ||
@@ -90,3 +93,3 @@ "call_get.js": true, | ||
var CONSTANTS_FILE = './src/constants.js'; | ||
var BUILD_DEBUG_DEST = "./js/main/bluebird.js"; | ||
var BUILD_DEBUG_DEST = "./js/debug/bluebird.js"; | ||
@@ -227,2 +230,4 @@ var license; | ||
"./src/any.js", | ||
"./src/race.js", | ||
"./src/race_promise_array.js", | ||
"./src/call_get.js", | ||
@@ -248,3 +253,2 @@ "./src/filter.js", | ||
"./src/settled_promise_array.js", | ||
"./src/any_promise_array.js", | ||
"./src/some_promise_array.js", | ||
@@ -260,2 +264,6 @@ "./src/properties_promise_array.js", | ||
if( !isCI ) { | ||
gruntConfig.jshint.all.options.reporter = require("jshint-stylish"); | ||
} | ||
gruntConfig.bump = { | ||
@@ -410,2 +418,3 @@ options: { | ||
"./src/any.js", | ||
"./src/race.js", | ||
"./src/call_get.js", | ||
@@ -440,3 +449,3 @@ "./src/filter.js", | ||
"./src/settled_promise_array.js", | ||
"./src/any_promise_array.js", | ||
"./src/race_promise_array.js", | ||
"./src/some_promise_array.js", | ||
@@ -612,3 +621,3 @@ "./src/properties_promise_array.js", | ||
grunt.registerTask( "build", function() { | ||
var isCI = !!grunt.option("ci"); | ||
var done = this.async(); | ||
@@ -615,0 +624,0 @@ var features = grunt.option("features"); |
@@ -25,11 +25,14 @@ /** | ||
var AnyPromiseArray = require( "./any_promise_array.js" )(PromiseArray); | ||
var SomePromiseArray = require( "./some_promise_array.js" )(PromiseArray); | ||
function Promise$_Any( promises, useBound, caller ) { | ||
return Promise$_All( | ||
var ret = Promise$_All( | ||
promises, | ||
AnyPromiseArray, | ||
SomePromiseArray, | ||
caller, | ||
useBound === true ? promises._boundTo : void 0 | ||
).promise(); | ||
); | ||
ret.setHowMany( 1 ); | ||
ret.setUnwrap(); | ||
return ret.promise(); | ||
} | ||
@@ -36,0 +39,0 @@ |
@@ -63,2 +63,2 @@ /** | ||
}; | ||
}; | ||
}; |
@@ -124,3 +124,8 @@ /** | ||
if( newLen === 0 ) { | ||
this._fulfill( newValues ); | ||
if( fulfillValueIfEmpty === 1 ) { | ||
this._fulfill( newValues ); | ||
} | ||
else { | ||
this._fulfill( toFulfillmentValue( fulfillValueIfEmpty ) ); | ||
} | ||
return; | ||
@@ -216,2 +221,2 @@ } | ||
return PromiseArray; | ||
}; | ||
}; |
@@ -955,2 +955,3 @@ /** | ||
require('./any.js')(Promise,Promise$_All,PromiseArray); | ||
require('./race.js')(Promise,Promise$_All,PromiseArray); | ||
require('./call_get.js')(Promise); | ||
@@ -957,0 +958,0 @@ require('./filter.js')(Promise,Promise$_All,PromiseArray,apiRejection); |
@@ -31,3 +31,3 @@ /** | ||
this._howMany = 0; | ||
this._unwrap = false; | ||
} | ||
@@ -38,3 +38,2 @@ inherits( SomePromiseArray, PromiseArray ); | ||
this._init$( void 0, 1 ); | ||
var isArrayResolved = isArray( this._values ); | ||
@@ -53,2 +52,6 @@ this._holes = isArrayResolved | ||
SomePromiseArray.prototype.setUnwrap = function SomePromiseArray$setUnwrap() { | ||
this._unwrap = true; | ||
}; | ||
SomePromiseArray.prototype.howMany = function SomePromiseArray$howMany() { | ||
@@ -70,3 +73,8 @@ return this._howMany; | ||
this._values.length = this.howMany(); | ||
this._fulfill( this._values ); | ||
if( this.howMany() === 1 && this._unwrap ) { | ||
this._fulfill( this._values[0] ); | ||
} | ||
else { | ||
this._fulfill( this._values ); | ||
} | ||
} | ||
@@ -114,2 +122,2 @@ | ||
return SomePromiseArray; | ||
}; | ||
}; |
@@ -25,11 +25,14 @@ /** | ||
var AnyPromiseArray = require( "./any_promise_array.js" )(PromiseArray); | ||
var SomePromiseArray = require( "./some_promise_array.js" )(PromiseArray); | ||
function Promise$_Any( promises, useBound, caller ) { | ||
return Promise$_All( | ||
var ret = Promise$_All( | ||
promises, | ||
AnyPromiseArray, | ||
SomePromiseArray, | ||
caller, | ||
useBound === true ? promises._boundTo : void 0 | ||
).promise(); | ||
); | ||
ret.setHowMany( 1 ); | ||
ret.setUnwrap(); | ||
return ret.promise(); | ||
} | ||
@@ -36,0 +39,0 @@ |
@@ -63,2 +63,2 @@ /** | ||
}; | ||
}; | ||
}; |
@@ -124,3 +124,8 @@ /** | ||
if( newLen === 0 ) { | ||
this._fulfill( newValues ); | ||
if( fulfillValueIfEmpty === 1 ) { | ||
this._fulfill( newValues ); | ||
} | ||
else { | ||
this._fulfill( toFulfillmentValue( fulfillValueIfEmpty ) ); | ||
} | ||
return; | ||
@@ -216,2 +221,2 @@ } | ||
return PromiseArray; | ||
}; | ||
}; |
@@ -951,2 +951,3 @@ /** | ||
require('./any.js')(Promise,Promise$_All,PromiseArray); | ||
require('./race.js')(Promise,Promise$_All,PromiseArray); | ||
require('./call_get.js')(Promise); | ||
@@ -953,0 +954,0 @@ require('./filter.js')(Promise,Promise$_All,PromiseArray,apiRejection); |
@@ -31,3 +31,3 @@ /** | ||
this._howMany = 0; | ||
this._unwrap = false; | ||
} | ||
@@ -38,3 +38,2 @@ inherits( SomePromiseArray, PromiseArray ); | ||
this._init$( void 0, 1 ); | ||
var isArrayResolved = isArray( this._values ); | ||
@@ -53,2 +52,6 @@ this._holes = isArrayResolved | ||
SomePromiseArray.prototype.setUnwrap = function SomePromiseArray$setUnwrap() { | ||
this._unwrap = true; | ||
}; | ||
SomePromiseArray.prototype.howMany = function SomePromiseArray$howMany() { | ||
@@ -70,3 +73,8 @@ return this._howMany; | ||
this._values.length = this.howMany(); | ||
this._fulfill( this._values ); | ||
if( this.howMany() === 1 && this._unwrap ) { | ||
this._fulfill( this._values[0] ); | ||
} | ||
else { | ||
this._fulfill( this._values ); | ||
} | ||
} | ||
@@ -114,2 +122,2 @@ | ||
return SomePromiseArray; | ||
}; | ||
}; |
{ | ||
"name": "bluebird", | ||
"description": "Full featured Promises/A+ implementation with exceptionally good performance", | ||
"version": "0.9.8-0", | ||
"version": "0.9.9-0", | ||
"keywords": [ | ||
"promise", | ||
"performance", | ||
"fast", | ||
"promises", | ||
"promises-a", | ||
"promises-aplus", | ||
"async" | ||
"async", | ||
"await", | ||
"deferred", | ||
"deferreds", | ||
"future", | ||
"flow control", | ||
"dsl", | ||
"fluent interface" | ||
], | ||
@@ -47,3 +55,4 @@ "scripts": { | ||
"text-table": "~0.2.0", | ||
"grunt-cli": "~0.1.9" | ||
"grunt-cli": "~0.1.9", | ||
"jshint-stylish": "~0.1.3" | ||
}, | ||
@@ -50,0 +59,0 @@ "readmeFilename": "README.md", |
@@ -38,3 +38,3 @@ [![Build Status](https://travis-ci.org/petkaantonov/bluebird.png?branch=master)](https://travis-ci.org/petkaantonov/bluebird) | ||
- [Complete parallel for C# 5.0 async and await](https://github.com/petkaantonov/bluebird/blob/master/API.md#promisecoroutinegeneratorfunction-generatorfunction---function) | ||
- [Collection methods](https://github.com/petkaantonov/bluebird/blob/master/API.md#collections) such as All, any, some, settle, map, filter, reduce, spread, join... | ||
- [Collection methods](https://github.com/petkaantonov/bluebird/blob/master/API.md#collections) such as All, any, some, settle, map, filter, reduce, spread, join, race... | ||
- [Practical debugging solutions](#error-handling) such as unhandled rejection reporting, typed catches, catching only what you expect and very long, relevant stack traces without losing perf | ||
@@ -522,2 +522,3 @@ - [Sick performance](https://github.com/petkaantonov/bluebird/tree/master/benchmark/stats) | ||
<tr><td><a href="https://github.com/petkaantonov/bluebird/blob/master/API.md#any---promise"><code>.any</code></a> and <a href="https://github.com/petkaantonov/bluebird/blob/master/API.md#promiseanyarraydynamicpromise-values---promise"><code>Promise.any</code></a></td><td><code>any</code></td></tr> | ||
<tr><td><a href="https://github.com/petkaantonov/bluebird/blob/master/API.md#race---promise"><code>.race</code></a> and <a href="https://github.com/petkaantonov/bluebird/blob/master/API.md#promiseracearraypromise-promises---promise"><code>Promise.race</code></a></td><td><code>race</code></td></tr> | ||
<tr><td><a href="https://github.com/petkaantonov/bluebird/blob/master/API.md#callstring-propertyname--dynamic-arg---promise"><code>.call</code></a> and <a href="https://github.com/petkaantonov/bluebird/blob/master/API.md#getstring-propertyname---promise"><code>.get</code></a></td><td><code>call_get</code></td></tr> | ||
@@ -524,0 +525,0 @@ <tr><td><a href="https://github.com/petkaantonov/bluebird/blob/master/API.md#filterfunction-filterer---promise"><code>.filter</code></a> and <a href="https://github.com/petkaantonov/bluebird/blob/master/API.md#promisefilterarraydynamicpromise-values-function-filterer---promise"><code>Promise.filter</code></a></td><td><code>filter</code></td></tr> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
434199
88
9046
667
19