Skip to content

Commit 5ed55b8

Browse files
mapAsyncIterator: add default value for 'rejectCallback' (#3011)
1 parent ecf732f commit 5ed55b8

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/subscription/mapAsyncIterator.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import type { PromiseOrValue } from '../jsutils/PromiseOrValue';
77
export function mapAsyncIterator<T, U>(
88
iterable: AsyncIterable<T> | AsyncGenerator<T, void, void>,
99
callback: (T) => PromiseOrValue<U>,
10-
rejectCallback?: (any) => PromiseOrValue<U>,
10+
rejectCallback: (any) => PromiseOrValue<U> = (error) => {
11+
throw error;
12+
},
1113
): AsyncGenerator<U, void, void> {
1214
// $FlowFixMe[prop-missing]
1315
const iteratorMethod = iterable[Symbol.asyncIterator];
@@ -28,12 +30,11 @@ export function mapAsyncIterator<T, U>(
2830
: asyncMapValue(result.value, callback).then(iteratorResult, abruptClose);
2931
}
3032

31-
let mapReject;
32-
if (rejectCallback) {
33-
// Capture rejectCallback to ensure it cannot be null.
34-
const reject = rejectCallback;
35-
mapReject = (error: mixed) =>
36-
asyncMapValue(error, reject).then(iteratorResult, abruptClose);
33+
function mapReject(error: mixed) {
34+
return asyncMapValue(error, rejectCallback).then(
35+
iteratorResult,
36+
abruptClose,
37+
);
3738
}
3839

3940
/* TODO: Flow doesn't support symbols as keys:

0 commit comments

Comments
 (0)