Skip to content

Commit

Permalink
Fix uncaught exceptions
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Candeia <[email protected]>
  • Loading branch information
mcandeia committed May 29, 2024
1 parent 66185cb commit d4a91f0
Show file tree
Hide file tree
Showing 2 changed files with 15 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.1.0",
"version": "0.1.1",
"exports": "./mod.ts",
"tasks": {
"start": "deno run -A main.ts"
Expand Down
18 changes: 14 additions & 4 deletions handlers.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,21 @@ const onWsOpened: ClientMessageHandler<DataEndMessage> = async (state, message)
const socketChan = await makeWebSocket<ArrayBuffer, ArrayBuffer>(socket, false);
request.socketChan = socketChan.out;
(async () => {
for await (const msg of socketChan.in.recv()) {
await state.ch.out.send({ type: "ws-message", id: message.id, data: msg });
try {
for await (const msg of socketChan.in.recv()) {
await state.ch.out.send({ type: "ws-message", id: message.id, data: msg });
}
await state.ch.out.send({ type: "ws-closed", id: message.id })
socket.close();
} catch (error) {
console.log("sending through a closed channel error", error, message);
} finally {
try {
socket.close();
} catch (_err) {
// ignore
}
}
await state.ch.out.send({ type: "ws-closed", id: message.id })
socket.close();
})()
}
catch (err) {
Expand Down

0 comments on commit d4a91f0

Please sign in to comment.