Ask questionsQ&A: Can you close the server manually?

Thanks for maintaining this project!

I want to close down the Oak server each test.

application.listen({ port });
application.close(); // <-- Something like this 

Is this possible?



Answer questions kitsonk

@adoi abort signals are the browser standard for aborting asynchronous processes, I would prefer to align to that. From an overall architecture perspective, I am not convinced that the ability to close the server and stop processing requests should be an implicit API offered up to middleware. The ability to allow middleware to do that should be explicit. For example is someone wanted to create a middleware library that needed to close the server, the would have a constructor (or factory) that would take the abort controller as an argument. This would ensure that the consumer of the middleware is explicit of allowing the middleware to potentially close the server:

import { Application } from "";
import { SomeMiddleware } from "https://some.lib/mod.ts";

const abortController = new AbortController();
const { signal } = abortController;
const app = new App({ signal });
const app.use(new SomeMiddleware({ abortController }));

Is there an example of a library otherwise compatible with oak that is simply missing a server close()?

oak doesn't aim to be compatible with middleware that wasn't written for it. It is fully embracing Deno and Deno's patterns as well as trying to cut down on the n number of ways to do something that I feel is a challenge with koa and koa-router.


Related questions

No questions were found.
Github User Rank List