Skip to content

Commit

Permalink
add some private struct comment docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmills committed Nov 17, 2022
1 parent 4544203 commit 1c37d68
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,36 @@ func newSignalReceivers() signalReceivers {
}

type signalReceivers struct {
m sync.Mutex
signals chan os.Signal
// this mutex protects writes and reads of this struct to prevent
// race conditions in a parallel execution pattern
m sync.Mutex

// our os.Signal channel we relay from
signals chan os.Signal
// when written to, will instruct the signal relayer to shutdown
shutdown chan struct{}
// is written to when signal relay has finished shutting down
finished chan struct{}
notify func(c chan<- os.Signal, sig ...os.Signal)

// this stub allows us to unit test signal relay functionality
notify func(c chan<- os.Signal, sig ...os.Signal)

// last will contain a pointer to the last ShutdownSignal received, or
// nil if none, if a new channel is created by Wait or Done, this last
// signal will be immediately written to, this allows Wait or Done state
// to be read after application stop
last *ShutdownSignal

// contains channels created by Done
done []chan os.Signal

// contains channels created by Wait
wait []chan ShutdownSignal
}

func (recv *signalReceivers) relayer(ctx context.Context) {
defer func() {
recv.finished <- struct{}{}
recv.finished <- struct{}{}
}()

select {
Expand Down

0 comments on commit 1c37d68

Please sign in to comment.