-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any way to cancel the request? #19
Comments
Okay, thanks. I'll keep an eye out for that. |
Our current user base is chrome only, any chance there's a browser-specific hack we could use as a shim until this in place? |
@jonnyreeves I downloaded the latest and tried it out. The chunkedRequest function doesn't appear to return anything. From your example it seems like you're expecting it to return a promise? |
@ajselvig - please see #22 for context. If you can migrate your implementation to use jonnyreeves/fetch-readablestream then you can use the Apologies for the churn; hope this works out for you - if you have further issues please let me know and I can help resolve them. |
@jonnyreeves - I'm trying to set up my solution to use fetchStream instead of chunkedRequest. I have a working implementation, except that I'm no longer getting the chunks as they come in, just one big response at the end. Any chance you could tell me what's wrong with the implementation? I'm having some trouble interpreting the various parts. (sorry for the coffeescript) readAllChunks = (readableStream) ->
reader = readableStream.getReader()
chunks = []
pump = ->
return reader.read().then((data) ->
if (data.done)
return chunks
chunks.push(data.value)
return pump()
)
pump()
decodeResponse = (chunks) ->
decoder = new TextDecoder()
return chunks
.map((bytes, idx) ->
isLastChunk = (idx == (chunks.length - 1))
return decoder.decode(bytes, { stream: !isLastChunk })
).join('')
decodeUnaryJSON = (chunks) ->
new Promise((resolve) ->
json = decodeResponse(chunks)
resolve(
_.map(json.split(/}\s*{/), (row) ->
row = row.trim()
unless row.startsWith('{')
row = '{' + row
unless row.endsWith('}')
row = row + '}'
JSON.parse(row)
)
)
)
fetchStream(url, {
method: 'POST'
headers: {accept: 'application/json'}
credentials: 'include'
body: JSON.stringify(data)
})
.then((response) -> readAllChunks(response.body))
.then(decodeUnaryJSON)
.then((chunks) =>
@listener.onChunks chunks
) |
Is there any way to cancel the request (like xhr.abort())? We're using this for potentially long running requests and it would be nice to be able to let the user cancel it in the middle.
The text was updated successfully, but these errors were encountered: