Skip to content

Commit

Permalink
add serving check
Browse files Browse the repository at this point in the history
  • Loading branch information
liujianping committed Sep 29, 2020
1 parent 8e9dd01 commit 6402727
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tcpserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ func (srv *Server) errorf(format string, a ...interface{}) {

//Serve tcpserver serving
func (srv *Server) Serve(ctx context.Context) error {
defer srv.stopped.Fire()

if srv.handler == nil {
return fmt.Errorf("tcpserver.Handler required")
}
Expand All @@ -146,6 +144,8 @@ func (srv *Server) Serve(ctx context.Context) error {
if srv.tls != nil {
srv.listener = tls.NewListener(srv.listener, srv.tls)
}
//flags
defer srv.stopped.Fire()
srv.serving.Fire()
//add context cancel
ctx, cancel := context.WithCancel(ctx)
Expand Down Expand Up @@ -184,6 +184,11 @@ func (srv *Server) Serve(ctx context.Context) error {
}
}

//Serving check
func (srv *Server) Serving() <-chan struct{} {
return srv.serving.Done()
}

//Close tcpserver waiting all connections finished
func (srv *Server) Close() <-chan struct{} {
if srv.serving.HasFired() {
Expand Down

0 comments on commit 6402727

Please sign in to comment.