From 4264ab6dc3f0fcc13fdbe779b618ebc193836f59 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Fri, 23 Sep 2022 14:39:50 -0500 Subject: [PATCH] Poblem 3 time --- main.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/main.ts b/main.ts index 01e0b25..443e7d5 100644 --- a/main.ts +++ b/main.ts @@ -1,4 +1,4 @@ -import * as bytes from "https://deno.land/x/bytes@1.0.3/mod.ts"; +import { ByteSet } from "https://deno.land/x/bytes@1.0.3/mod.ts"; import { JsonParseStream } from "https://deno.land/std@0.157.0/encoding/json/stream.ts"; import { TextLineStream } from "https://deno.land/std@0.156.0/streams/delimiter.ts"; import { writeAll, copy } from "https://deno.land/std@0.156.0/streams/conversion.ts"; @@ -11,7 +11,7 @@ console.log(`Listening on 0.0.0.0:${PORT}`) for await (const conn of listener) { console.log('Connection established:', conn.remoteAddr) try { - primeTime(conn) + meansToAnEnd(conn) } catch (e) { console.error(conn.remoteAddr, e) } @@ -20,12 +20,13 @@ for await (const conn of listener) { // problem 2 async function meansToAnEnd(conn) { + new ByteSet( } // problem 1 async function primeTime(conn) { try { - for await (const request of jsons(conn)) { + for await (const request of jsonLines(conn)) { console.log('Request:', request) if (request.method == "isPrime" && typeof request.number == "number") { const response = { @@ -50,7 +51,7 @@ function isPrime(n) { return n > 1 } -function jsons(conn) { +function jsonLines(conn) { const readable = conn.readable .pipeThrough(new TextDecoderStream()) .pipeThrough(new TextLineStream())