Skip to content

Commit

Permalink
Cancel req send on abort signal
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Candeia <[email protected]>
  • Loading branch information
mcandeia committed Jun 1, 2024
1 parent 371927b commit f7525bf
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 15 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.2.3",
"version": "0.2.4",
"exports": "./mod.ts",
"tasks": {
"check": "deno fmt && deno lint && deno check mod.ts"
Expand Down
1 change: 1 addition & 0 deletions handlers.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const error: ServerMessageHandler<ErrorMessage> = (state) => {
state.live = false;
};


/**
* Handler for the 'request-start' server message.
* @param {ClientState} state - The client state.
Expand Down
10 changes: 0 additions & 10 deletions handlers.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ const onResponseStart: ClientMessageHandler<ResponseStartMessage> = (
const data: ClientMessageHandler<DataMessage> = async (state, message) => {
const request = state.ongoingRequests[message.id];
if (!request) {
console.error(
new Date(),
"Didn't find response object, unable to send data",
message.id,
);
return;
}
try {
Expand All @@ -89,10 +84,6 @@ const data: ClientMessageHandler<DataMessage> = async (state, message) => {
const onDataEnd: ClientMessageHandler<DataEndMessage> = (state, message) => {
const request = state.ongoingRequests[message.id];
if (!request) {
console.error(
new Date(),
"Didn't find response object, unable to send data",
);
return;
}
if (message.error) {
Expand Down Expand Up @@ -240,7 +231,6 @@ export const handleClientMessage: ClientMessageHandler = async (
state,
message,
) => {
console.info(new Date(), message.type, "id" in message ? message.id : "");
await handlersByType?.[message.type]?.(state, message)?.catch?.((err) => {
console.error(
"unexpected error happening when handling message",
Expand Down
8 changes: 4 additions & 4 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,19 @@ export const serveHandler = (
responseBodyChan: makeChan(),
};
try {
const signal = ch.out.signal;
await ch.out.send(requestForward);
const dataChan = req.body ? makeChanStream(req.body) : undefined;
const linked = link(ch.out.signal, req.signal);
(async () => {
try {
for await (const chunk of dataChan?.recv(signal) ?? []) {
for await (const chunk of dataChan?.recv(linked) ?? []) {
await ch.out.send({
type: "request-data",
id: messageId,
chunk,
});
}
if (signal.aborted) {
if (linked.aborted) {
return;
}
await ch.out.send({
Expand All @@ -179,7 +179,7 @@ export const serveHandler = (
status: 503,
}),
);
if (signal.aborted) {
if (linked.aborted) {
return;
}
console.log(
Expand Down

0 comments on commit f7525bf

Please sign in to comment.