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>

authored by

danielkaxis
Gustav Tiger
and committed by
GitHub
e7697fb7 0b307a91

+8 -7
+5
.changeset/healthy-hornets-warn.md
··· 1 + --- 2 + '@urql/exchange-execute': patch 3 + --- 4 + 5 + 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
··· 49 49 args: ExecuteParams 50 50 ): Source<OperationResult> => { 51 51 return make<OperationResult>(observer => { 52 + let iterator: AsyncIterator<ExecutionResult>; 52 53 let ended = false; 53 54 54 55 Promise.resolve() ··· 66 67 observer.next(makeResult(operation, result as ExecutionResult)); 67 68 return; 68 69 } 69 - 70 - const iterator: AsyncIterator<ExecutionResult> = result[ 71 - asyncIterator! 72 - ](); 70 + iterator = result[asyncIterator!](); 73 71 let prevResult: OperationResult | null = null; 74 72 75 73 function next({ ··· 90 88 if (!done && !ended) { 91 89 return iterator.next().then(next); 92 90 } 93 - if (ended) { 94 - iterator.return && iterator.return(); 95 - } 96 91 } 97 92 98 93 return iterator.next().then(next); ··· 106 101 }); 107 102 108 103 return () => { 104 + if (iterator && iterator.return) iterator.return(); 109 105 ended = true; 110 106 }; 111 107 });