Skip to content

Commit ce68f97

Browse files
authored
refactor(incremental): close stream iterator only on abnormal stop (#4641)
1 parent 87e2929 commit ce68f97

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/execution/incremental/IncrementalExecutor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,8 +751,8 @@ export class IncrementalExecutor<
751751
cancelStreamItems.forEach((cancelStreamItem) =>
752752
cancelStreamItem(reason),
753753
);
754+
returnIteratorCatchingErrors(iterator);
754755
}
755-
returnIteratorCatchingErrors(iterator);
756756
});
757757
await (enableEarlyExecution ? Promise.resolve() : started);
758758
if (stopRequested) {

src/execution/incremental/__tests__/stream-test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,10 +2784,12 @@ describe('Execute: stream directive', () => {
27842784
const iterable = {
27852785
[Symbol.asyncIterator]: () => ({
27862786
next: () => {
2787-
const friend = friends[index++];
2788-
if (friend == null) {
2789-
return Promise.resolve({ done: true, value: undefined });
2787+
if (index > 1) {
2788+
return new Promise(() => {
2789+
// never resolves
2790+
});
27902791
}
2792+
const friend = friends[index++];
27912793
return Promise.resolve({ done: false, value: friend });
27922794
},
27932795
return: () => {

src/execution/legacyIncremental/__tests__/legacy-stream-test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2703,10 +2703,12 @@ describe('Execute: stream directive (legacy)', () => {
27032703
const iterable = {
27042704
[Symbol.asyncIterator]: () => ({
27052705
next: () => {
2706-
const friend = friends[index++];
2707-
if (friend == null) {
2708-
return Promise.resolve({ done: true, value: undefined });
2706+
if (index > 1) {
2707+
return new Promise(() => {
2708+
// never resolves
2709+
});
27092710
}
2711+
const friend = friends[index++];
27102712
return Promise.resolve({ done: false, value: friend });
27112713
},
27122714
return: () => {

0 commit comments

Comments
 (0)