There is a public method ShutdownContexthere, which allows context param to be passed. But the method ListenAndServe does not accept context param and always uses context.Background in listenTCP(...) or listenUDP(...) when called from the method ListenAndServer(...).
I know I can construct the listeners myself and use the ActivateAndServe. But it seems to be too much effort when someone is not willing to take on the burden of setting up and maintaining the listeners on their end and only want to pass down context.
I think the easiest way is
Add a public context field Ctx in the Server struct.
Populate it with the default value context.Background() in init() method if not previously set by the user.
Refactor two function listenTCP, listenUDP to accept and use the context parameter.
In method ListenerAndServe, invoke listenTCP, listenUDP with srv.Ctx.
If there are no objections, I am happy to make the change and submit the PR.
Hi there,
There is a public method
ShutdownContext
here, which allows context param to be passed. But the methodListenAndServe
does not accept context param and always usescontext.Background
in listenTCP(...) or listenUDP(...) when called from the method ListenAndServer(...).I know I can construct the listeners myself and use the
ActivateAndServe
. But it seems to be too much effort when someone is not willing to take on the burden of setting up and maintaining the listeners on their end and only want to pass down context.I think the easiest way is
Ctx
in theServer
struct.context.Background()
ininit()
method if not previously set by the user.listenTCP
,listenUDP
to accept and use the context parameter.ListenerAndServe
, invokelistenTCP
,listenUDP
withsrv.Ctx
.If there are no objections, I am happy to make the change and submit the PR.