pgjones / hypercorn

Hypercorn is an ASGI and WSGI Server based on Hyper libraries and inspired by Gunicorn.
MIT License
1.11k stars 102 forks source link

Readyness callback in `serve()` function. #96

Open jonathanslenders opened 1 year ago

jonathanslenders commented 1 year ago

It would be good if the serve (and/or maybe worker_serve) functions can accept a callback (or any other mechanism) to signal readiness to its caller. Something similar to anyio's TaskStatus, an Event or a pure callback. Maybe an Event is the easiest.

The problem is that this function is supposed to run forever, so when it's integrated in an application, we can't distinguish between "we are still starting up and still have to bind the socket (but will possibly fail soon due to port already in use)" and "we're up and running".

septatrix commented 1 year ago

If you are only concerned about binding you could perform the bind yourself and pass the fds to the config object. Apart from that there are also the lifespan events like startup and startup.complete