Skip to content

Commit

Permalink
pref: used single context instead of chan
Browse files Browse the repository at this point in the history
Signed-off-by: Sanskarzz <[email protected]>
  • Loading branch information
Sanskarzz committed Mar 14, 2024
1 parent 02410ee commit 265cb66
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"log"
"net"
"net/http"
"os"
"os/signal"
"syscall"
"time"
Expand Down Expand Up @@ -73,18 +72,17 @@ func (s *Servers) startGRPCServer(ctx context.Context) {
}

func main() {
httpCtx, httpCancel := context.WithCancel(context.Background())
grpcCtx, grpcCancel := context.WithCancel(context.Background())

ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer cancel()
srv := NewServers()
go srv.startHTTPServer(httpCtx)
go srv.startGRPCServer(grpcCtx)
done := make(chan os.Signal, 1)
signal.Notify(done, syscall.SIGINT, syscall.SIGTERM)

<-done
httpCancel()
grpcCancel()
time.Sleep(5 * time.Second)
go srv.startHTTPServer(ctx)
go srv.startGRPCServer(ctx)

go func() {
<-ctx.Done()
cancel()
}()
select {}
}

0 comments on commit 265cb66

Please sign in to comment.