@@ -485,9 +485,15 @@ var Aff = function () {
485
485
}
486
486
}
487
487
joins = null ;
488
+ // If we have an interrupt and a fail, then the thread threw while
489
+ // running finalizers. This should always rethrow in a fresh stack.
490
+ if ( interrupt && fail ) {
491
+ setTimeout ( function ( ) {
492
+ throw util . fromLeft ( fail ) ;
493
+ } , 0 ) ;
488
494
// If we have an unhandled exception, and no other fiber has joined
489
495
// then we need to throw the exception in a fresh stack.
490
- if ( util . isLeft ( step ) && rethrow ) {
496
+ } else if ( util . isLeft ( step ) && rethrow ) {
491
497
setTimeout ( function ( ) {
492
498
// Guard on reathrow because a completely synchronous fiber can
493
499
// still have an observer which was added after-the-fact.
@@ -532,12 +538,8 @@ var Aff = function () {
532
538
533
539
var canceler = onComplete ( {
534
540
rethrow : false ,
535
- handler : function ( result ) {
536
- if ( fail ) {
537
- return cb ( fail ) ;
538
- } else {
539
- return cb ( util . right ( void 0 ) ) ;
540
- }
541
+ handler : function ( /* unused */ ) {
542
+ return cb ( util . right ( void 0 ) ) ;
541
543
}
542
544
} ) ( ) ;
543
545
@@ -634,7 +636,6 @@ var Aff = function () {
634
636
// cancellation fibers.
635
637
function kill ( error , par , cb ) {
636
638
var step = par ;
637
- var fail = null ;
638
639
var head = null ;
639
640
var tail = null ;
640
641
var count = 0 ;
@@ -651,11 +652,8 @@ var Aff = function () {
651
652
kills [ count ++ ] = tmp . kill ( error , function ( result ) {
652
653
return function ( ) {
653
654
count -- ;
654
- if ( fail === null && util . isLeft ( result ) ) {
655
- fail = result ;
656
- }
657
655
if ( count === 0 ) {
658
- cb ( fail || util . right ( void 0 ) ) ( ) ;
656
+ cb ( result ) ( ) ;
659
657
}
660
658
} ;
661
659
} ) ;
@@ -688,7 +686,7 @@ var Aff = function () {
688
686
}
689
687
690
688
if ( count === 0 ) {
691
- cb ( fail || util . right ( void 0 ) ) ( ) ;
689
+ cb ( util . right ( void 0 ) ) ( ) ;
692
690
} else {
693
691
// Run the cancelation effects. We alias `count` because it's mutable.
694
692
kid = 0 ;
@@ -795,19 +793,15 @@ var Aff = function () {
795
793
kid = killId ++ ;
796
794
// Once a side has resolved, we need to cancel the side that is still
797
795
// pending before we can continue.
798
- kills [ kid ] = kill ( early , step === lhs ? head . _2 : head . _1 , function ( killResult ) {
796
+ kills [ kid ] = kill ( early , step === lhs ? head . _2 : head . _1 , function ( /* unused */ ) {
799
797
return function ( ) {
800
798
delete kills [ kid ] ;
801
- if ( util . isLeft ( killResult ) ) {
802
- fail = killResult ;
803
- step = null ;
804
- }
805
799
if ( tmp ) {
806
800
tmp = false ;
807
801
} else if ( tail === null ) {
808
- join ( fail || step , null , null ) ;
802
+ join ( step , null , null ) ;
809
803
} else {
810
- join ( fail || step , tail . _1 , tail . _2 ) ;
804
+ join ( step , tail . _1 , tail . _2 ) ;
811
805
}
812
806
} ;
813
807
} ) ;
0 commit comments