-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add shutdown timeout #2514
Add shutdown timeout #2514
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package beater | ||
|
||
import "time" | ||
|
||
type signalWait struct { | ||
count int // number of potential 'alive' signals | ||
signals chan struct{} | ||
} | ||
|
||
func newSignalWait() *signalWait { | ||
return &signalWait{ | ||
signals: make(chan struct{}, 1), | ||
} | ||
} | ||
|
||
func (s *signalWait) Wait() { | ||
if s.count == 0 { | ||
return | ||
} | ||
|
||
<-s.signals | ||
s.count-- | ||
} | ||
|
||
func (s *signalWait) Add(fn func()) { | ||
s.count++ | ||
go func() { | ||
fn() | ||
var v struct{} | ||
s.signals <- v | ||
}() | ||
} | ||
|
||
func (s *signalWait) AddChan(c <-chan struct{}) { | ||
s.Add(func() { <-c }) | ||
} | ||
|
||
func (s *signalWait) AddTimer(t *time.Timer) { | ||
s.Add(func() { <-t.C }) | ||
} | ||
|
||
func (s *signalWait) AddTimeout(d time.Duration) { | ||
s.AddTimer(time.NewTimer(d)) | ||
} | ||
|
||
func (s *signalWait) Signal() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this needed for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's for sending inserting a signal. E.g. having received Ctrl-C one can use e.g.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it |
||
s.Add(func() {}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add here a log message that shutdown will wait for time X to shutdown or success