@@ -23,12 +23,14 @@ export function mapAsyncIterator<T, U>(
2323 throw error ;
2424 }
2525
26- async function mapResult ( result : IteratorResult < T , void > ) {
27- if ( result . done ) {
28- return result ;
29- }
30-
26+ async function mapResult ( resultPromise : Promise < IteratorResult < T , void >> ) {
3127 try {
28+ const result = await resultPromise ;
29+
30+ if ( result . done ) {
31+ return result ;
32+ }
33+
3234 return { value : await callback ( result . value ) , done : false } ;
3335 } catch ( callbackError ) {
3436 return abruptClose ( callbackError ) ;
@@ -39,16 +41,16 @@ export function mapAsyncIterator<T, U>(
3941 https://github.com/facebook/flow/issues/3258 */
4042 return ( {
4143 next ( ) : Promise < IteratorResult < U , void>> {
42- return iterator . next ( ) . then ( mapResult , abruptClose ) ;
44+ return mapResult ( iterator . next ( ) ) ;
4345 } ,
4446 return ( ) {
4547 return typeof iterator . return === 'function'
46- ? iterator . return ( ) . then ( mapResult , abruptClose )
48+ ? mapResult ( iterator . return ( ) )
4749 : Promise . resolve ( { value : undefined , done : true } ) ;
4850 } ,
4951 throw ( error ?: mixed ) : Promise < IteratorResult < U , void >> {
5052 if ( typeof iterator . throw === 'function' ) {
51- return iterator . throw ( error ) . then ( mapResult , abruptClose ) ;
53+ return mapResult ( iterator . throw ( error ) ) ;
5254 }
5355 return Promise . reject ( error ) . catch ( abruptClose ) ;
5456 } ,
0 commit comments