Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.

fix(execute): end iterator on teardown (#2803)

Co-authored-by: Gustav Tiger <Gustav.Tiger@axis.com>

Co-authored-by: Gustav Tiger <Gustav.Tiger@axis.com>

Changed files
+8 -7
.changeset
exchanges
execute
+5
.changeset/healthy-hornets-warn.md
···
+
---
+
'@urql/exchange-execute': patch
+
---
+
+
End iterator when teardown functions runs, previously it waited for one extra call to next, then ended the iterator
+3 -7
exchanges/execute/src/execute.ts
···
args: ExecuteParams
): Source<OperationResult> => {
return make<OperationResult>(observer => {
+
let iterator: AsyncIterator<ExecutionResult>;
let ended = false;
Promise.resolve()
···
observer.next(makeResult(operation, result as ExecutionResult));
return;
}
-
-
const iterator: AsyncIterator<ExecutionResult> = result[
-
asyncIterator!
-
]();
+
iterator = result[asyncIterator!]();
let prevResult: OperationResult | null = null;
function next({
···
if (!done && !ended) {
return iterator.next().then(next);
}
-
if (ended) {
-
iterator.return && iterator.return();
-
}
}
return iterator.next().then(next);
···
});
return () => {
+
if (iterator && iterator.return) iterator.return();
ended = true;
};
});