fix: use webstream
parent
a5fde51eeb
commit
f69aaef6d7
|
|
@ -1,4 +1,4 @@
|
|||
import { io } from "../../deps.ts";
|
||||
import { readLines } from "../utils.ts";
|
||||
import { Transport } from "./types.ts";
|
||||
|
||||
export class DenoIO implements Transport {
|
||||
|
|
@ -8,7 +8,7 @@ export class DenoIO implements Transport {
|
|||
reader: ReadableStream<Uint8Array>;
|
||||
writer: WritableStream<Uint8Array>;
|
||||
}) {
|
||||
this.lines = io.readLines(reader);
|
||||
this.lines = readLines(reader);
|
||||
this.writer = writer;
|
||||
}
|
||||
async recv(): Promise<string | undefined> {
|
||||
|
|
@ -21,10 +21,13 @@ export class DenoIO implements Transport {
|
|||
return undefined;
|
||||
}
|
||||
async send(data: string) {
|
||||
await writeAll(
|
||||
this.writer,
|
||||
new TextEncoder().encode(data + "\n"),
|
||||
);
|
||||
const writer = this.writer.getWriter();
|
||||
try {
|
||||
await writer.ready;
|
||||
await writer.write(new TextEncoder().encode(data + "\n"));
|
||||
} finally {
|
||||
writer.releaseLock();
|
||||
}
|
||||
}
|
||||
async close() {
|
||||
await this.writer.close();
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@ import {
|
|||
import { base64, uuid } from "../deps.ts";
|
||||
import { Env } from "./env.ts";
|
||||
|
||||
async function* _readlines() {
|
||||
export async function* readLines(readable: ReadableStream<Uint8Array>) {
|
||||
const decoder = new TextDecoder();
|
||||
let buffer = "";
|
||||
|
||||
for await (const chunk of Deno.stdin.readable) {
|
||||
for await (const chunk of readable) {
|
||||
buffer += decoder.decode(chunk);
|
||||
let lineEndIndex;
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ async function* _readlines() {
|
|||
}
|
||||
}
|
||||
|
||||
const stdinLines = _readlines();
|
||||
const stdinLines = readLines(Deno.stdin.readable);
|
||||
export async function readline(
|
||||
{ skipEmpty = true }: { skipEmpty?: boolean } = {},
|
||||
) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue