Skip to content

Commit

Permalink
docs: Update TypeScript docs to use AbortController
Browse files Browse the repository at this point in the history
Signed-off-by: Felicitas Pojtinger <felicitas@pojtinger.com>
  • Loading branch information
pojntfx committed Aug 15, 2024
1 parent 526cb38 commit 3a6ff98
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,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) {
Expand Down Expand Up @@ -1123,9 +1125,12 @@ server.on("connection", (socket) => {
socket.addEventListener("close", () => {
parserReader.cancel();
parserWriter.abort();
linkSignal.abort();
});

registry.linkStream(
linkSignal.signal,

encoder,
decoder,

Expand Down Expand Up @@ -1234,6 +1239,8 @@ await new Promise<void>((res, rej) => {
socket.addEventListener("error", rej);
});

const linkSignal = new AbortController();

// Set up streaming JSON encoder
const encoder = new WritableStream({
write(chunk) {
Expand Down Expand Up @@ -1273,9 +1280,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,

Expand Down

0 comments on commit 3a6ff98

Please sign in to comment.