File tree Expand file tree Collapse file tree
typescript/gql-client/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -58,10 +58,21 @@ export function createParser<
5858 const reader = rStream . getReader ( )
5959 const decoder = new TextDecoder ( )
6060 let shouldClose = false
61- const close = ( ) => shouldClose = true
61+ type ReadResult = Awaited < ReturnType < typeof reader . read > >
62+ let resolve : ( v : ReadResult ) => void
63+ const signal = new Promise < ReadResult > (
64+ res => resolve = res
65+ )
66+ const close = ( ) => {
67+ shouldClose = true
68+ resolve ( { done : true , value : undefined } )
69+ }
6270 const stream = async function * ( ) {
6371 while ( ! shouldClose ) {
64- const readResult = await reader . read ( )
72+ const readResult = await Promise . race ( [
73+ reader . read ( ) ,
74+ signal
75+ ] )
6576 if ( readResult . done || shouldClose ) break
6677 const lines = decoder . decode ( readResult . value )
6778 . split ( '\n' )
You can’t perform that action at this time.
0 commit comments