Closed byene0923 closed 5 months ago
The engine closes all the conns in Stop(), but OnClose callback is executed async. The sleep here is for the OnClose to do some clean work. It's not a perfect duration, it's just an estimated duration. Most of the time we don't need to wait for that cleaning work, but waiting for a little moment may be a little better, and 1/5 s doesn't matter too much.
yeah, i understand , that's good, is there a better way, such as graceful shutdown?give a way for user to choose whther wait for OnClose()? i dont know how other network frame to deal with this
Here is engine shutdown: https://github.com/lesismal/nbio/blob/master/engine.go#L239
Users can wg.Add() in OnOpen and wg.Done() in OnClose and wg.Wait() after engine.Shutdown().
So, removing the sleep is also fine.
hello, I don't know the use of
time.Sleep(time.Second / 5)
inEngine.Stop()
, maybe for test but forget to delete it?