@@ -14,14 +14,16 @@ export function mapAsyncIterator<T, U>(
14
14
// $FlowFixMe[prop-missing]
15
15
const iteratorMethod = iterable [ Symbol . asyncIterator ] ;
16
16
const iterator : any = iteratorMethod . call ( iterable ) ;
17
- let $return : any ;
18
- let abruptClose ;
19
- if ( typeof iterator . return === 'function' ) {
20
- $return = iterator . return ;
21
- abruptClose = ( error : mixed ) => {
22
- const rethrow = ( ) => Promise . reject ( error ) ;
23
- return $return . call ( iterator ) . then ( rethrow , rethrow ) ;
24
- } ;
17
+
18
+ async function abruptClose ( error : mixed ) {
19
+ if ( typeof iterator . return === 'function' ) {
20
+ try {
21
+ await iterator . return ( ) ;
22
+ } catch ( _e ) {
23
+ /* ignore error */
24
+ }
25
+ }
26
+ throw error ;
25
27
}
26
28
27
29
async function mapResult ( result : IteratorResult < T , void > ) {
@@ -51,8 +53,8 @@ export function mapAsyncIterator<T, U>(
51
53
return iterator . next ( ) . then ( mapResult , mapReject ) ;
52
54
} ,
53
55
return ( ) {
54
- return $ return
55
- ? $return . call ( iterator ) . then ( mapResult , mapReject )
56
+ return typeof iterator . return === 'function'
57
+ ? iterator . return ( ) . then ( mapResult , mapReject )
56
58
: Promise . resolve ( { value : undefined , done : true } ) ;
57
59
} ,
58
60
throw ( error ?: mixed ) : Promise < IteratorResult < U , void >> {
0 commit comments