From 5fb5509f60280a85ce6babcbcdd8400b9e45e627 Mon Sep 17 00:00:00 2001 From: Contextualist Date: Wed, 14 Feb 2024 16:48:09 -0800 Subject: [PATCH] chore: edge: make `deno check` pass --- edge/index.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/edge/index.ts b/edge/index.ts index 562b40f..f148354 100644 --- a/edge/index.ts +++ b/edge/index.ts @@ -77,7 +77,8 @@ async function handleExchangeV1(req: Request, connInfo: ConnInfo): Promise void}>() +type ResolveStr = (x: string) => void +const inbox = new Map() async function exchange(name: string, x0: string, conn: ReadableStreamBYOBReader): Promise { if (inbox.has(name)) { // the other party has set up an in-memory exchange @@ -89,7 +90,7 @@ async function exchange(name: string, x0: string, conn: ReadableStreamBYOBReader const [x1, source] = await Promise.any([ // attempt to set up an in-memory exchange - new Promise((resolve) => { + new Promise((resolve: ResolveStr) => { inbox.set(name, { xa: x0, xb_resolve: resolve }) }).then((x) => [x, "in-memory"]), // attempt to do cross-regional exchange @@ -114,7 +115,7 @@ async function exchangeViaBroadcastChannel(name: string, x0: string): Promise { + const x1 = await (new Promise((resolve: ResolveStr) => { channel.onmessage = (event: MessageEvent) => resolve(event.data) })) channel.postMessage(x0) // if the other party subscribes after the first post @@ -136,14 +137,14 @@ function joinHostPort(addr: Deno.NetAddr): string { async function receivePacket(conn: ReadableStreamBYOBReader): Promise { - let buf = (await conn.read(new Uint8Array(2))).value + let buf = (await conn.read(new Uint8Array(2))).value! const lenCap = 1e3 const plen = (buf[0]<<8) | buf[1] // uint16, BE if (plen == 0 || plen > lenCap) { console.error(`received suspicious packet header declearing len=${plen}`) throw new Deno.errors.InvalidData } - buf = (await conn.read(new Uint8Array(plen))).value + buf = (await conn.read(new Uint8Array(plen))).value! return buf } @@ -151,7 +152,7 @@ async function receivePacket(conn: ReadableStreamBYOBReader): Promise>8)&0xff, l&0xff])) // uint16, BE + p.set([(l>>8)&0xff, l&0xff]) // uint16, BE p.set(data, 2) return p }