// Generate a new context
ctx := NewContext()
// Run service with this context
go func(ctx context.Context) {
if err := ExitWaitGroupAdd(ctx, 1); err != nil {
return
}
defer ExitWaitGroupDone(ctx)
otherEvent := make(chan struct{})
FOR_LOOP:
for {
select {
case <-ctx.Done():
break FOR_LOOP
case <-otherEvent:
// ...
}
}
// Some close processes
}(ctx)
// Wait interrupt signal and shutdown gracefully
if err := WaitAndShutdown(ctx, time.Second*5, func(timeout time.Duration) error {
log.Println("close")
return nil
}); err != nil {
log.Println("Shutdown error:", err)
return
}
-
Notifications
You must be signed in to change notification settings - Fork 2
Gracefully shutdown using context.Context and sync.GroupWait
License
zhangpeihao/shutdown
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Gracefully shutdown using context.Context and sync.GroupWait
Topics
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published