Poblem 3 time

This commit is contained in:
Daniel Flanagan 2022-09-23 14:39:50 -05:00
parent 0cc8b61df3
commit 4264ab6dc3
Signed by untrusted user: lytedev-divvy
GPG key ID: 6D69CEEE4ABBCD82

View file

@ -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())