vans163
07/27/2021, 6:47 PMvans163
07/27/2021, 6:47 PMvans163
07/27/2021, 6:47 PMjohn.spurlock
07/27/2021, 9:58 PMSubh
07/28/2021, 6:47 PMWallacy
07/28/2021, 9:30 PMjohn.spurlock
07/28/2021, 9:32 PMWallacy
07/28/2021, 9:37 PMjohn.spurlock
07/28/2021, 9:39 PMvans163
07/28/2021, 10:40 PMvans163
07/28/2021, 10:40 PMvans163
07/28/2021, 10:40 PMvans163
07/28/2021, 10:52 PMvans163
07/28/2021, 10:52 PMvans163
07/28/2021, 10:55 PMvans163
07/28/2021, 10:59 PMjavascript
async fetch(request) {
if (request.headers.get("Upgrade") == "websocket") {
let pair = new WebSocketPair();
var websocket = pair[1];
var session = {websocket: websocket, last_ping: Date.now()};
this.sessions.push(session);
websocket.accept();
websocket.addEventListener("message", async msg=> {
session.last_ping = Date.now();
});
return new Response(null, { status: 101, webSocket: pair[0] });
}
if (request.method === "POST" || request.method == "PUT") {
const { readable, writable } = new TransformStream()
const reader = readable.getReader({ mode: "byob" })
request.body.pipeTo(writable)
await this.constantly_read_body(reader)
return new Response("", {status: 200});
}
return new Response("oops", {status: 400});
}
async constantly_read_body() {
while(1) {
send_message_to_do_2("ping");
send_msg_to_websocket("ping");
const { value, done } = await reader.read(this.buffer);
if (done)
break;
}
}
basically as long as constantly_read_body fetch request is running (even tho it breaks on the await), no IO is sent out the DO if that IO originates on the same fetch request context.
send_message_to_do_2("ping");
send_msg_to_websocket("ping");
Both get queued up. As soon as the fetch dies (say I kill it manually), the queue starts flushing and do_2 as well as connect websocket get a flood of msgs.
Note I can connect 5+ websockets while the fetch is running, its just the websockets dont get any msgs that originate (if the caller is) from the fetch request. The actual accept happens.vans163
07/28/2021, 11:04 PMvans163
07/28/2021, 11:05 PMvans163
07/28/2021, 11:12 PMconst { readable2, writable2 } = new TransformStream()
return new Response(readable2, {status: 200});
Deleted User
07/29/2021, 1:07 PMbrett
07/29/2021, 1:46 PMbrett
07/29/2021, 1:49 PMzifera
07/29/2021, 1:49 PMzifera
07/29/2021, 1:51 PMbrett
07/29/2021, 1:51 PMjohn.spurlock
07/29/2021, 1:52 PMbrett
07/29/2021, 1:53 PMbrett
07/29/2021, 1:54 PMzifera
07/29/2021, 1:54 PMjohn.spurlock
07/29/2021, 1:55 PM