Poblem 3 time
This commit is contained in:
parent
0cc8b61df3
commit
4264ab6dc3
9
main.ts
9
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())
|
||||
|
|
Loading…
Reference in a new issue