From 526cb380dc7f4476cecbb71e556c20d769689e71 Mon Sep 17 00:00:00 2001 From: Felicitas Pojtinger Date: Wed, 14 Aug 2024 17:30:28 -0700 Subject: [PATCH] feat: Port rest of panrpc examples to context/signal-aware API in TypeScript version Signed-off-by: Felicitas Pojtinger --- ts/bin/panrpc-example-websocket-client-cli.ts | 10 ++++++++++ .../app/page.tsx | 5 +++++ .../bun.lockb | Bin 160696 -> 160696 bytes ...rpc-example-websocket-coffee-client-cli.ts | 5 +++++ ...rpc-example-websocket-coffee-server-cli.ts | 5 +++++ ts/bin/panrpc-example-websocket-server-cli.ts | 10 ++++++++++ 6 files changed, 35 insertions(+) diff --git a/ts/bin/panrpc-example-websocket-client-cli.ts b/ts/bin/panrpc-example-websocket-client-cli.ts index b1ed5bc..4785f3b 100644 --- a/ts/bin/panrpc-example-websocket-client-cli.ts +++ b/ts/bin/panrpc-example-websocket-client-cli.ts @@ -110,6 +110,8 @@ if (listen) { console.error("Client disconnected with error:", e); }); + const linkSignal = new AbortController(); + const encoder = new WritableStream({ write(chunk) { socket.send(JSON.stringify(chunk)); @@ -149,9 +151,12 @@ if (listen) { socket.addEventListener("close", () => { parserReader.cancel(); parserWriter.abort(); + linkSignal.abort(); }); registry.linkStream( + linkSignal.signal, + encoder, decoder, @@ -176,6 +181,8 @@ if (listen) { socket.addEventListener("error", rej); }); + const linkSignal = new AbortController(); + const encoder = new WritableStream({ write(chunk) { socket.send(JSON.stringify(chunk)); @@ -215,9 +222,12 @@ if (listen) { socket.addEventListener("close", () => { parserReader.cancel(); parserWriter.abort(); + linkSignal.abort(); }); registry.linkStream( + linkSignal.signal, + encoder, decoder, diff --git a/ts/bin/panrpc-example-websocket-client-web/app/page.tsx b/ts/bin/panrpc-example-websocket-client-web/app/page.tsx index 5b6e003..e54e0e0 100644 --- a/ts/bin/panrpc-example-websocket-client-web/app/page.tsx +++ b/ts/bin/panrpc-example-websocket-client-web/app/page.tsx @@ -52,6 +52,8 @@ export default function Home() { socket.addEventListener("error", rej); }); + const linkSignal = new AbortController(); + const encoder = new WritableStream({ write(chunk) { socket.send(JSON.stringify(chunk)); @@ -91,9 +93,12 @@ export default function Home() { socket.addEventListener("close", () => { parserReader.cancel(); parserWriter.abort(); + linkSignal.abort(); }); registry.linkStream( + linkSignal.signal, + encoder, decoder, diff --git a/ts/bin/panrpc-example-websocket-client-web/bun.lockb b/ts/bin/panrpc-example-websocket-client-web/bun.lockb index f2f2f5a866a7b37d5c70b4d87dcf7dfab0a69512..9a04e860ef37eee7638b84456f685646b11567f4 100755 GIT binary patch delta 3532 zcmXxmX^azf7{~Dr>=qVwXIU18U5)`2tD+R~Mc-NDo4zuY7%ed-O-QuHXlmk%dPKV- zNd=FJEZcHuxvK&eP$_uTyIwGgN&%H3D#Zhf2iCj#{C>~hhWR{CzcZcPo%+JPC%g8Z z?Ap0|#IlCVBMU`42NSeHojgi1zp&f#`7B?%w=Hu_zHhd5g>-in&ZekG1FKQev_^w# zP%^YmLu*m8v_ZpQroW9v{#)W05koR+D*0VP2z)Y*uVq*dx} zLP=4N1~#LlX^jTApk!#BhKeXz+MwYlP;#_MBTu3fXp2UlLMhTVjcr9KQU5mVaayMK zc9aCIQ0HlsB&|}ngp#5j4eUTk(;5x#M9I)P4edh7(gqDbgOa078hI9_KwC8W97>V4 zX>2!2iTcaf~UJA_UkAKTA|JxC`nqS?wcqn>e0YkC}~=w!756I z)@kT%lq_w~@H;3u+N6dI( zp;c<*P9ZemP@r(r> zEgjKr#-fh4j#v+4Nr&I&ySR?B4!f5zp`)V1nZTITQPtu0F{X5QIsy|J(>iK8g8hsc z9d#X{NsL(?4ISahj5!@m9TA7IprfTDI)$;Qqpc%0z*y4ZALP5Zjlj7`8}rfNU}^z=jT5lw-_>~dgatU z+3{=ND-*Y!Ajf{$@w(4k*C)GY+LHWYxy8^@bE;oX9h4onSSAyzIq=Gv=E~k9j}Bi?-ZXqgy`zUjd95;Wmh3xaA18CQX=lm4 zSay6TYfL*^_A|2MA+ME*ujL#$P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%;^pTSsAqoqb-CSy^Jwi-#Bv8+Z%jnpj0iW;FB=>f*78j(Rh%c$Y2Va;aD zs!>zJ9%9U?QCGv6!|19Js1cpZn3pkf<>2LG1CBYcqAw%=29rNyk}NzjrOVcs{lnMl zJWi6=#UsXb(y$#bYqf6I>o!5!40W23)h!~=XUdYN#tj0lHBr`pZY!j9%N}n%PZl04 zrOBVg1C#LzdE8t&CZFk2R}SE9r^vcf?{87(8~7(B-$2H#y7kE3)R(xev}CPZ;&y$g zR}LMNJwEmwGI7~yvJS}}kGwvwPxgUs!=+VniQ&8Sp?*1ZSoZjqck6~ba6~sxCN7IR zFkUwJ=BxF2w(O_swnn#E(t7X$d92k9cdA#PcdxqMurVlcNXK>h#M#o$(=RUQHiRY% zxA#8X=E(jgS$N#9+g#cA$Zf(;@qliQ?0faCTdx~_qEU0$Feb}pM92BEUnP6o{|&mG zCHvE|#|@SL5AbI>TlObpj~lv4ru-S_$ZG4hS+@n!PU^Nrw{xYX^q1Q@tYcK-LW%h1 z+jPUXU8GOkuG{(2rt5D~mWE&a0$EqcdARTnX*j%4)=b&p{E9SO=0aJvZaek$hA)yh zpf9*fzj%?fL4D#L{obLj+gpmgJU^PbX~_2$ab$`SLLx%f(PS&L=OkXPgD;N#DdHCQ?}V)mO$ cN~dJlxb_@bay?_2togEE+%;xxFn1sQA4e62bpQYW diff --git a/ts/bin/panrpc-example-websocket-coffee-client-cli.ts b/ts/bin/panrpc-example-websocket-coffee-client-cli.ts index cc2415e..29eb0b7 100644 --- a/ts/bin/panrpc-example-websocket-coffee-client-cli.ts +++ b/ts/bin/panrpc-example-websocket-coffee-client-cli.ts @@ -134,6 +134,8 @@ await new Promise((res, rej) => { socket.addEventListener("error", rej); }); +const linkSignal = new AbortController(); + // Set up streaming JSON encoder const encoder = new WritableStream({ write(chunk) { @@ -173,9 +175,12 @@ socket.addEventListener("message", (m) => parserWriter.write(m.data as string)); socket.addEventListener("close", () => { parserReader.cancel(); parserWriter.abort(); + linkSignal.abort(); }); registry.linkStream( + linkSignal.signal, + encoder, decoder, diff --git a/ts/bin/panrpc-example-websocket-coffee-server-cli.ts b/ts/bin/panrpc-example-websocket-coffee-server-cli.ts index ef92d8f..0a08a2d 100644 --- a/ts/bin/panrpc-example-websocket-coffee-server-cli.ts +++ b/ts/bin/panrpc-example-websocket-coffee-server-cli.ts @@ -124,6 +124,8 @@ server.on("connection", (socket) => { console.error("Remote control disconnected with error:", e); }); + const linkSignal = new AbortController(); + // Set up streaming JSON encoder const encoder = new WritableStream({ write(chunk) { @@ -165,9 +167,12 @@ server.on("connection", (socket) => { socket.addEventListener("close", () => { parserReader.cancel(); parserWriter.abort(); + linkSignal.abort(); }); registry.linkStream( + linkSignal.signal, + encoder, decoder, diff --git a/ts/bin/panrpc-example-websocket-server-cli.ts b/ts/bin/panrpc-example-websocket-server-cli.ts index d71236e..9cd6bdc 100644 --- a/ts/bin/panrpc-example-websocket-server-cli.ts +++ b/ts/bin/panrpc-example-websocket-server-cli.ts @@ -106,6 +106,8 @@ if (listen) { console.error("Client disconnected with error:", e); }); + const linkSignal = new AbortController(); + const encoder = new WritableStream({ write(chunk) { socket.send(JSON.stringify(chunk)); @@ -145,9 +147,12 @@ if (listen) { socket.addEventListener("close", () => { parserReader.cancel(); parserWriter.abort(); + linkSignal.abort(); }); registry.linkStream( + linkSignal.signal, + encoder, decoder, @@ -172,6 +177,8 @@ if (listen) { socket.addEventListener("error", rej); }); + const linkSignal = new AbortController(); + const encoder = new WritableStream({ write(chunk) { socket.send(JSON.stringify(chunk)); @@ -211,9 +218,12 @@ if (listen) { socket.addEventListener("close", () => { parserReader.cancel(); parserWriter.abort(); + linkSignal.abort(); }); registry.linkStream( + linkSignal.signal, + encoder, decoder,