Skip to content
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

Windows service #1070

Merged
merged 11 commits into from
Nov 15, 2017
10 changes: 2 additions & 8 deletions agent/app/agent_windows.go
Original file line number Diff line number Diff line change
@@ -175,14 +175,8 @@ func (h *handler) runAgent(ctx context.Context) {

// sleepCtx provides a cancelable sleep
func sleepCtx(ctx context.Context, duration time.Duration) {
Copy link
Member

@jahkeup jahkeup Nov 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can instead use the stdlib (or golang.org/x/net) context.WithDeadline function and wait on ctx.Done() of that context.

done := make(chan struct{})
time.AfterFunc(duration, func() {
close(done)
})
select {
case <-ctx.Done():
case <-done:
}
derivedCtx, _ := context.WithDeadline(ctx, time.Now().Add(duration))
<-derivedCtx.Done()
}

type termHandlerIndicator struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the way this indicator struct is being used. Out of curiosity -- is this implementing anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I'm aware of, but I didn't do a very deep search yet.