Skip to content

Commit

Permalink
Parallel req/resp body write
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 215d151 commit 215d434
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 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.1",
"version": "0.2.2",
"exports": "./mod.ts",
"tasks": {
"check": "deno fmt && deno lint && deno check mod.ts"
Expand Down
6 changes: 4 additions & 2 deletions handlers.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,18 @@ async function doFetch(
});
const body = response?.body;
const stream = body ? makeChanStream(body) : undefined;
const messages = [];
for await (const chunk of stream?.recv(signal) ?? []) {
await clientCh.send({
messages.push(clientCh.send({
type: "data",
id: request.id,
chunk,
});
}));
}
if (signal.aborted) {
return;
}
await Promise.all(messages);
await clientCh.send({
type: "data-end",
id: request.id,
Expand Down
6 changes: 4 additions & 2 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,18 @@ export const serveHandler = (
const dataChan = req.body ? makeChanStream(req.body) : undefined;
(async () => {
try {
const messages = [];
for await (const chunk of dataChan?.recv(signal) ?? []) {
await ch.out.send({
messages.push(ch.out.send({
type: "request-data",
id: messageId,
chunk,
});
}));
}
if (signal.aborted) {
return;
}
await Promise.all(messages);
await ch.out.send({
type: "request-end",
id: messageId,
Expand Down

0 comments on commit 215d434

Please sign in to comment.