Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SafeClose ¶
type SafeClose struct {
// contains filtered or unexported fields
}
SafeClose can achieve safe close where WaitClosed returns only after all sub goroutines exited.
- Main service goroutine starts and wait on ReceiveCloseSignal.
- Any service's sub goroutine should be started by Attach and wait on ReceiveCloseSignal.
- If any fatal err occurs, any service goroutine can call SendCloseSignal to close the service.
- Any third party caller can call SendCloseSignal to close the service.
func NewSafeClose ¶
func NewSafeClose() *SafeClose
func (*SafeClose) Attach ¶
func (s *SafeClose) Attach(f func(done func(), closeSignal <-chan struct{}))
Attach add this goroutine to s.wg WaitClosed. f must receive closeSignal and call done when it is done. If s was closed, f will not run.
func (*SafeClose) ReceiveCloseSignal ¶
func (s *SafeClose) ReceiveCloseSignal() <-chan struct{}
func (*SafeClose) SendCloseSignal ¶
SendCloseSignal sends a close signal. Unblock WaitClosed. The given error will be read by WaitClosed. Once SendCloseSignal is called, following calls are noop.
func (*SafeClose) WaitClosed ¶
WaitClosed waits until all SendCloseSignal is called and all attached funcs in SafeClose are done.
Click to show internal directories.
Click to hide internal directories.