fix: update stream message guest-js

pull/2479/head
adrieljss 5 months ago
parent ca3651b55d
commit 0a0a428094
No known key found for this signature in database
GPG Key ID: 849F13CBD0B4AD05

@ -113,11 +113,7 @@ export interface StreamMessage {
/** /**
* The chunk - an array of bytes sent from Rust. * The chunk - an array of bytes sent from Rust.
*/ */
value?: ArrayBuffer | number[] bytes: Uint8Array
/**
* Is the stream done.
*/
done: boolean
} }
const ERROR_REQUEST_CANCELLED = 'Request canceled' const ERROR_REQUEST_CANCELLED = 'Request canceled'
@ -207,8 +203,11 @@ export async function fetch(
streamChannel.onmessage = (res: StreamMessage) => { streamChannel.onmessage = (res: StreamMessage) => {
// close early if aborted // close early if aborted
if (signal?.aborted) controller.error(ERROR_REQUEST_CANCELLED) if (signal?.aborted) controller.error(ERROR_REQUEST_CANCELLED)
if (res.done) controller.close() if (!res.bytes.length) {
controller.enqueue(res.value) controller.close()
return
}
controller.enqueue(res)
} }
} }
}) })

Loading…
Cancel
Save