This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +21
-9
lines changed
Expand file tree Collapse file tree 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) {
364364 counter = promises . length ,
365365 results = [ ] ;
366366
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+ } ) ;
375377 } ) ;
376- } ) ;
378+ } else {
379+ deferred . resolve ( results ) ;
380+ }
377381
378382 return deferred . promise ;
379383 }
Original file line number Diff line number Diff line change @@ -676,6 +676,14 @@ describe('q', function() {
676676
677677
678678 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+
679687 it ( 'should take an array of promises and return a promise for an array of results' , function ( ) {
680688 var deferred1 = defer ( ) ,
681689 deferred2 = defer ( ) ;
You can’t perform that action at this time.
0 commit comments