From 0a0a4280946a3de0d15984c42d532c6451fffe69 Mon Sep 17 00:00:00 2001 From: adrieljss Date: Mon, 3 Mar 2025 12:50:02 +0800 Subject: [PATCH] fix: update stream message guest-js --- plugins/http/guest-js/index.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/plugins/http/guest-js/index.ts b/plugins/http/guest-js/index.ts index 6c163509..836f2aad 100644 --- a/plugins/http/guest-js/index.ts +++ b/plugins/http/guest-js/index.ts @@ -113,11 +113,7 @@ export interface StreamMessage { /** * The chunk - an array of bytes sent from Rust. */ - value?: ArrayBuffer | number[] - /** - * Is the stream done. - */ - done: boolean + bytes: Uint8Array } const ERROR_REQUEST_CANCELLED = 'Request canceled' @@ -207,8 +203,11 @@ export async function fetch( streamChannel.onmessage = (res: StreamMessage) => { // close early if aborted if (signal?.aborted) controller.error(ERROR_REQUEST_CANCELLED) - if (res.done) controller.close() - controller.enqueue(res.value) + if (!res.bytes.length) { + controller.close() + return + } + controller.enqueue(res) } } })