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

Service interface: add GetExitChan function #9

Closed
wants to merge 1 commit into from
Closed

Service interface: add GetExitChan function #9

wants to merge 1 commit into from

Conversation

mdh67899
Copy link

see nsqio/nsq#1140, thanks。

@mdh67899 mdh67899 closed this Feb 27, 2019
@judwhite
Copy link
Owner

judwhite commented Feb 1, 2021

@mdh67899 I believe this is addressed with the addition of the Context interface (thanks @jehiah)

go-svc/svc.go

Lines 49 to 54 in 054d56d

// Context interface contains an optional Context function which a Service can implement.
// When implemented the context.Done() channel will be used in addition to signal handling
// to exit a process.
type Context interface {
Context() context.Context
}

Example:

go-svc/example/main.go

Lines 14 to 31 in 054d56d

type program struct {
LogFile *os.File
svr *server
ctx context.Context
}
func (p *program) Context() context.Context {
return p.ctx
}
func main() {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancel()
prg := program{
svr: &server{},
ctx: ctx,
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants