@@ -818,48 +818,59 @@ async function completeAsyncIteratorValue(
818818 let containsPromise = false ;
819819 const completedResults : Array < unknown > = [ ] ;
820820 let index = 0 ;
821- // eslint-disable-next-line no-constant-condition
822- while ( true ) {
823- const itemPath = addPath ( path , index , undefined ) ;
824- let iteration ;
825- try {
826- // eslint-disable-next-line no-await-in-loop
827- iteration = await asyncIterator . next ( ) ;
828- } catch ( rawError ) {
829- throw locatedError ( rawError , fieldGroup , pathToArray ( path ) ) ;
830- }
821+ const earlyReturn = asyncIterator . return ?. bind ( asyncIterator ) ;
822+ try {
823+ // eslint-disable-next-line no-constant-condition
824+ while ( true ) {
825+ const itemPath = addPath ( path , index , undefined ) ;
826+ let iteration ;
827+ try {
828+ // eslint-disable-next-line no-await-in-loop
829+ iteration = await asyncIterator . next ( ) ;
830+ } catch ( rawError ) {
831+ throw locatedError ( rawError , fieldGroup , pathToArray ( path ) ) ;
832+ }
831833
832- if ( iteration . done ) {
833- break ;
834- }
834+ if ( iteration . done ) {
835+ break ;
836+ }
835837
836- const item = iteration . value ;
837- if ( isPromise ( item ) ) {
838- completedResults . push (
839- completePromisedListItemValue (
838+ const item = iteration . value ;
839+ if ( isPromise ( item ) ) {
840+ completedResults . push (
841+ completePromisedListItemValue (
842+ item ,
843+ exeContext ,
844+ itemType ,
845+ fieldGroup ,
846+ info ,
847+ itemPath ,
848+ ) ,
849+ ) ;
850+ containsPromise = true ;
851+ } else if (
852+ completeListItemValue (
840853 item ,
854+ completedResults ,
841855 exeContext ,
842856 itemType ,
843857 fieldGroup ,
844858 info ,
845859 itemPath ,
846- ) ,
847- ) ;
848- containsPromise = true ;
849- } else if (
850- completeListItemValue (
851- item ,
852- completedResults ,
853- exeContext ,
854- itemType ,
855- fieldGroup ,
856- info ,
857- itemPath ,
858- )
859- ) {
860- containsPromise = true ;
860+ )
861+ ) {
862+ containsPromise = true ;
863+ }
864+ index ++ ;
861865 }
862- index += 1 ;
866+ } catch ( error ) {
867+ if ( earlyReturn !== undefined ) {
868+ earlyReturn ( ) . catch ( ( ) => {
869+ /* c8 ignore next 1 */
870+ // ignore error
871+ } ) ;
872+ }
873+ throw error ;
863874 }
864875 return containsPromise ? Promise . all ( completedResults ) : completedResults ;
865876}
0 commit comments