@@ -485,9 +485,15 @@ var Aff = function () {
485485 }
486486 }
487487 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 ) ;
488494 // If we have an unhandled exception, and no other fiber has joined
489495 // then we need to throw the exception in a fresh stack.
490- if ( util . isLeft ( step ) && rethrow ) {
496+ } else if ( util . isLeft ( step ) && rethrow ) {
491497 setTimeout ( function ( ) {
492498 // Guard on reathrow because a completely synchronous fiber can
493499 // still have an observer which was added after-the-fact.
@@ -532,12 +538,8 @@ var Aff = function () {
532538
533539 var canceler = onComplete ( {
534540 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 ) ) ;
541543 }
542544 } ) ( ) ;
543545
@@ -634,7 +636,6 @@ var Aff = function () {
634636 // cancellation fibers.
635637 function kill ( error , par , cb ) {
636638 var step = par ;
637- var fail = null ;
638639 var head = null ;
639640 var tail = null ;
640641 var count = 0 ;
@@ -651,11 +652,8 @@ var Aff = function () {
651652 kills [ count ++ ] = tmp . kill ( error , function ( result ) {
652653 return function ( ) {
653654 count -- ;
654- if ( fail === null && util . isLeft ( result ) ) {
655- fail = result ;
656- }
657655 if ( count === 0 ) {
658- cb ( fail || util . right ( void 0 ) ) ( ) ;
656+ cb ( result ) ( ) ;
659657 }
660658 } ;
661659 } ) ;
@@ -688,7 +686,7 @@ var Aff = function () {
688686 }
689687
690688 if ( count === 0 ) {
691- cb ( fail || util . right ( void 0 ) ) ( ) ;
689+ cb ( util . right ( void 0 ) ) ( ) ;
692690 } else {
693691 // Run the cancelation effects. We alias `count` because it's mutable.
694692 kid = 0 ;
@@ -795,19 +793,15 @@ var Aff = function () {
795793 kid = killId ++ ;
796794 // Once a side has resolved, we need to cancel the side that is still
797795 // 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 */ ) {
799797 return function ( ) {
800798 delete kills [ kid ] ;
801- if ( util . isLeft ( killResult ) ) {
802- fail = killResult ;
803- step = null ;
804- }
805799 if ( tmp ) {
806800 tmp = false ;
807801 } else if ( tail === null ) {
808- join ( fail || step , null , null ) ;
802+ join ( step , null , null ) ;
809803 } else {
810- join ( fail || step , tail . _1 , tail . _2 ) ;
804+ join ( step , tail . _1 , tail . _2 ) ;
811805 }
812806 } ;
813807 } ) ;
0 commit comments