This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +21
-9
lines changed
2 files changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -364,16 +364,20 @@ function qFactory(nextTick, exceptionHandler) {
364
364
counter = promises . length ,
365
365
results = [ ] ;
366
366
367
- forEach ( promises , function ( promise , index ) {
368
- promise . then ( function ( value ) {
369
- if ( index in results ) return ;
370
- results [ index ] = value ;
371
- if ( ! ( -- counter ) ) deferred . resolve ( results ) ;
372
- } , function ( reason ) {
373
- if ( index in results ) return ;
374
- deferred . reject ( reason ) ;
367
+ if ( counter ) {
368
+ forEach ( promises , function ( promise , index ) {
369
+ ref ( promise ) . then ( function ( value ) {
370
+ if ( index in results ) return ;
371
+ results [ index ] = value ;
372
+ if ( ! ( -- counter ) ) deferred . resolve ( results ) ;
373
+ } , function ( reason ) {
374
+ if ( index in results ) return ;
375
+ deferred . reject ( reason ) ;
376
+ } ) ;
375
377
} ) ;
376
- } ) ;
378
+ } else {
379
+ deferred . resolve ( results ) ;
380
+ }
377
381
378
382
return deferred . promise ;
379
383
}
Original file line number Diff line number Diff line change @@ -676,6 +676,14 @@ describe('q', function() {
676
676
677
677
678
678
describe ( 'all' , function ( ) {
679
+ it ( 'should resolve all of nothing' , function ( ) {
680
+ var result ;
681
+ q . all ( [ ] ) . then ( function ( r ) { result = r ; } ) ;
682
+ mockNextTick . flush ( ) ;
683
+ expect ( result ) . toEqual ( [ ] ) ;
684
+ } ) ;
685
+
686
+
679
687
it ( 'should take an array of promises and return a promise for an array of results' , function ( ) {
680
688
var deferred1 = defer ( ) ,
681
689
deferred2 = defer ( ) ;
You can’t perform that action at this time.
0 commit comments