Skip to content

Commit

Permalink
Rename dataChan to responseBodyChan to make it more idiomatic
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Candeia <[email protected]>
  • Loading branch information
mcandeia committed May 31, 2024
1 parent 940bf14 commit ca1d951
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@deco/warp",
"version": "0.1.8",
"version": "0.1.9",
"exports": "./mod.ts",
"tasks": {
"check": "deno fmt && deno lint && deno check mod.ts"
Expand Down
14 changes: 6 additions & 8 deletions handlers.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ const onResponseStart: ClientMessageHandler<ResponseStartMessage> = (
headers.set(key, value);
});
const shouldBeNullBody = NULL_BODIES.includes(message.statusCode);
const stream = !shouldBeNullBody && request.dataChan
? makeReadableStream(request.dataChan)
const stream = !shouldBeNullBody && request.responseBodyChan
? makeReadableStream(request.responseBodyChan)
: undefined;
const resp = new Response(stream, {
status: message.statusCode,
Expand Down Expand Up @@ -75,7 +75,7 @@ const data: ClientMessageHandler<DataMessage> = async (state, message) => {
return;
}
try {
await request.dataChan?.send(ensureChunked(message.chunk));
await request.responseBodyChan?.send(ensureChunked(message.chunk));
} catch (_err) {
console.log("Request was aborted", _err);
}
Expand All @@ -102,9 +102,7 @@ const onDataEnd: ClientMessageHandler<DataEndMessage> = (state, message) => {
return;
}
try {
// Call ready again to ensure that all chunks are written
// before closing the writer.
request.dataChan?.close?.();
request.responseBodyChan?.close?.();
} catch (_err) {
console.log(_err);
}
Expand All @@ -128,7 +126,7 @@ const onWsClosed: ClientMessageHandler<WSConnectionClosed> = (
* @param {WSMessage} message - The message data.
*/
const onWsMessage: ClientMessageHandler<WSMessage> = async (state, message) => {
await state.ongoingRequests?.[message.id]?.socketChan?.send(message.data);
await state.ongoingRequests?.[message.id]?.webSocketChan?.send(message.data);
};

/**
Expand All @@ -151,7 +149,7 @@ const onWsOpened: ClientMessageHandler<DataEndMessage> = async (
socket,
false,
);
request.socketChan = socketChan.out;
request.webSocketChan = socketChan.out;
(async () => {
const signal = state.ch.out.signal;
try {
Expand Down
4 changes: 2 additions & 2 deletions messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export interface RequestObject {
id: string;
requestObject: Request;
responseObject: ReturnType<typeof Promise.withResolvers<Response>>;
dataChan?: Channel<Uint8Array>;
socketChan?: Channel<ArrayBuffer>;
responseBodyChan?: Channel<Uint8Array>;
webSocketChan?: Channel<ArrayBuffer>;
}

export interface RegisterMessage {
Expand Down
2 changes: 1 addition & 1 deletion server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export const serveHandler = (
id: messageId,
requestObject: req,
responseObject,
dataChan: makeChan(),
responseBodyChan: makeChan(),
};
try {
const signal = ch.out.signal;
Expand Down

0 comments on commit ca1d951

Please sign in to comment.