@@ -646,18 +646,20 @@ var Aff = function () {
646
646
647
647
switch ( step . tag ) {
648
648
case FORKED :
649
- tmp = fibers [ step . _1 ] ;
650
- kills [ count ++ ] = tmp . kill ( error , function ( result ) {
651
- return function ( ) {
652
- count -- ;
653
- if ( fail === null && util . isLeft ( result ) ) {
654
- fail = result ;
655
- }
656
- if ( count === 0 ) {
657
- cb ( fail || util . right ( void 0 ) ) ( ) ;
658
- }
659
- } ;
660
- } ) ;
649
+ if ( step . _3 === EMPTY ) {
650
+ tmp = fibers [ step . _1 ] ;
651
+ kills [ count ++ ] = tmp . kill ( error , function ( result ) {
652
+ return function ( ) {
653
+ count -- ;
654
+ if ( fail === null && util . isLeft ( result ) ) {
655
+ fail = result ;
656
+ }
657
+ if ( count === 0 ) {
658
+ cb ( fail || util . right ( void 0 ) ) ( ) ;
659
+ }
660
+ } ;
661
+ } ) ;
662
+ }
661
663
// Terminal case.
662
664
if ( head === null ) {
663
665
break loop;
@@ -685,11 +687,15 @@ var Aff = function () {
685
687
}
686
688
}
687
689
688
- // Run the cancelation effects. We alias `count` because it's mutable.
689
- kid = 0 ;
690
- tmp = count ;
691
- for ( ; kid < tmp ; kid ++ ) {
692
- kills [ kid ] = kills [ kid ] ( ) ;
690
+ if ( count === 0 ) {
691
+ cb ( fail || util . right ( void 0 ) ) ( ) ;
692
+ } else {
693
+ // Run the cancelation effects. We alias `count` because it's mutable.
694
+ kid = 0 ;
695
+ tmp = count ;
696
+ for ( ; kid < tmp ; kid ++ ) {
697
+ kills [ kid ] = kills [ kid ] ( ) ;
698
+ }
693
699
}
694
700
695
701
return kills ;
@@ -753,48 +759,64 @@ var Aff = function () {
753
759
// the first error.
754
760
if ( util . isLeft ( lhs ) ) {
755
761
if ( util . isLeft ( rhs ) ) {
756
- if ( step === lhs ) {
757
- step = rhs ;
762
+ if ( fail === lhs ) {
763
+ fail = rhs ;
758
764
}
759
765
} else {
760
- step = lhs ;
766
+ fail = lhs ;
761
767
}
768
+ step = null ;
769
+ head . _3 = fail ;
762
770
} else if ( util . isLeft ( rhs ) ) {
763
- step = rhs ;
771
+ step = null ;
772
+ fail = rhs ;
773
+ head . _3 = fail ;
764
774
} else {
765
- head . _3 = util . right ( util . fromRight ( lhs ) ( util . fromRight ( rhs ) ) ) ;
766
- step = head . _3 ;
775
+ step = util . right ( util . fromRight ( lhs ) ( util . fromRight ( rhs ) ) ) ;
776
+ head . _3 = step ;
767
777
}
768
778
break ;
769
779
case ALT :
770
- lhs = head . _1 . _3 ;
771
- rhs = head . _2 . _3 ;
772
- head . _3 = step ;
773
- tmp = true ;
774
- kid = killId ++ ;
775
- // Once a side has resolved, we need to cancel the side that is still
776
- // pending before we can continue.
777
- kills [ kid ] = kill ( early , step === lhs ? head . _2 : head . _1 , function ( killResult ) {
778
- return function ( ) {
779
- delete kills [ kid ] ;
780
- if ( util . isLeft ( killResult ) ) {
781
- fail = killResult ;
782
- step = null ;
783
- }
784
- if ( tmp ) {
785
- tmp = false ;
786
- } else if ( tail === null ) {
787
- join ( fail || step , null , null ) ;
788
- } else {
789
- join ( fail || step , tail . _1 , tail . _2 ) ;
790
- }
791
- } ;
792
- } ) ;
793
-
794
- if ( tmp ) {
795
- tmp = false ;
780
+ lhs = head . _1 . _3 ;
781
+ rhs = head . _2 . _3 ;
782
+ // We can only proceed if both have resolved or we have a success
783
+ if ( lhs === EMPTY && util . isLeft ( rhs ) || rhs === EMPTY && util . isLeft ( lhs ) ) {
796
784
return ;
797
785
}
786
+ // If both sides resolve with an error, we should continue with the
787
+ // first error
788
+ if ( lhs !== EMPTY && util . isLeft ( lhs ) && rhs !== EMPTY && util . isLeft ( rhs ) ) {
789
+ fail = step === lhs ? rhs : lhs ;
790
+ step = null ;
791
+ head . _3 = fail ;
792
+ } else {
793
+ head . _3 = step ;
794
+ tmp = true ;
795
+ kid = killId ++ ;
796
+ // Once a side has resolved, we need to cancel the side that is still
797
+ // pending before we can continue.
798
+ kills [ kid ] = kill ( early , step === lhs ? head . _2 : head . _1 , function ( killResult ) {
799
+ return function ( ) {
800
+ delete kills [ kid ] ;
801
+ if ( util . isLeft ( killResult ) ) {
802
+ fail = killResult ;
803
+ step = null ;
804
+ }
805
+ if ( tmp ) {
806
+ tmp = false ;
807
+ } else if ( tail === null ) {
808
+ join ( fail || step , null , null ) ;
809
+ } else {
810
+ join ( fail || step , tail . _1 , tail . _2 ) ;
811
+ }
812
+ } ;
813
+ } ) ;
814
+
815
+ if ( tmp ) {
816
+ tmp = false ;
817
+ return ;
818
+ }
819
+ }
798
820
break ;
799
821
}
800
822
0 commit comments