Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
rojvv committed Jun 6, 2024
1 parent 8ee1d99 commit fe6d357
Showing 1 changed file with 10 additions and 27 deletions.
37 changes: 10 additions & 27 deletions packages/shim-deno/src/deno/internal/Conn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,18 @@ export class Conn extends FsFile implements Deno.Conn {
}

async read(p: Uint8Array): Promise<number | null> {
let wait = false;
while (true) {
if (wait) {
try {
await once(this.#socket, "readable", {
signal: AbortSignal.timeout(5),
});
} catch (error) {
if (
!(error != null && typeof error === "object" && "name" in error &&
error.name == "AbortError")
) {
throw error;
}
}
wait = false;
}
try {
return await super.read(p);
} catch (error) {
if (
!(error != null && typeof error === "object" && "code" in error &&
error.code == "EAGAIN")
) {
throw error;
}
wait = true;
try {
return await super.read(p);
} catch (error) {
if (
!(error instanceof Error && "code" in error &&
error.code == "EAGAIN")
) {
throw error;
}
}
await once(this.#socket, "readable");
return await super.read(p);
}
}

Expand Down

0 comments on commit fe6d357

Please sign in to comment.