Skip to content

Commit

Permalink
fix: don't await respond
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Jun 6, 2024
1 parent 0a8aa42 commit ac90976
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 8 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oak/acorn",
"version": "0.6.0-alpha.3",
"version": "0.6.0-alpha.4",
"exports": {
".": "./mod.ts",
"./context": "./context.ts",
Expand Down
2 changes: 1 addition & 1 deletion http_server_node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Deno.test({
await server.listen();
const promise = fetch("http://localhost:8080/");
for await (const req of server) {
req.respond(new Response("hello world"));
req.respond(Promise.resolve(new Response("hello world")));
break;
}
const res = await promise;
Expand Down
5 changes: 0 additions & 5 deletions http_server_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@ class RequestEvent implements _RequestEvent {
}

get request(): Request {
console.log("read request");
return this.#request;
}

get response(): Promise<Response> {
console.log("read response");
return this.#promise;
}

Expand Down Expand Up @@ -89,12 +87,10 @@ class RequestEvent implements _RequestEvent {

// deno-lint-ignore no-explicit-any
error(reason?: any): void {
console.log("error", reason);
this.#reject(reason);
}

async respond(response: Response | PromiseLike<Response>): Promise<void> {
console.log("respond", response);
if (this.#resolved) {
throw new Error("Request already responded to.");
}
Expand Down Expand Up @@ -192,7 +188,6 @@ export default class HttpServer implements Server {
start: (controller) => {
this.#controller = controller;
const server = this.#server = createServer((req, res) => {
console.log("incoming", req, res);
controller.enqueue(
new RequestEvent(req, res, this.#host, this.#address),
);
Expand Down
2 changes: 1 addition & 1 deletion router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ export class Router extends EventTarget {
performance.mark(`${HANDLE_START} ${uid}`);
const { promise, resolve } = Promise.withResolvers<Response>();
this.#handling.add(promise);
await requestEvent.respond(promise);
requestEvent.respond(promise);
promise.then(() => this.#handling.delete(promise)).catch(
(error) => {
this.#error(requestEvent.request, error, false);
Expand Down

0 comments on commit ac90976

Please sign in to comment.