Skip to content

Commit 382dfe2

Browse files
mapAsyncIterator: simplify mapResult (#3013)
1 parent 6c53a27 commit 382dfe2

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

src/subscription/mapAsyncIterator.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,16 @@ export function mapAsyncIterator<T, U>(
2424
};
2525
}
2626

27-
function mapResult(result: IteratorResult<T, void>) {
28-
return result.done
29-
? result
30-
: asyncMapValue(result.value, callback).then(iteratorResult, abruptClose);
27+
async function mapResult(result: IteratorResult<T, void>) {
28+
if (result.done) {
29+
return result;
30+
}
31+
32+
try {
33+
return { value: await callback(result.value), done: false };
34+
} catch (callbackError) {
35+
return abruptClose(callbackError);
36+
}
3137
}
3238

3339
function mapReject(error: mixed) {
@@ -60,14 +66,3 @@ export function mapAsyncIterator<T, U>(
6066
},
6167
}: $FlowFixMe);
6268
}
63-
64-
function asyncMapValue<T, U>(
65-
value: T,
66-
callback: (T) => PromiseOrValue<U>,
67-
): Promise<U> {
68-
return new Promise((resolve) => resolve(callback(value)));
69-
}
70-
71-
function iteratorResult<T>(value: T): IteratorResult<T, void> {
72-
return { value, done: false };
73-
}

0 commit comments

Comments
 (0)