File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change 11package main
22
33import (
4+ "context"
45 "flag"
56 "fmt"
67 "math/rand"
@@ -95,6 +96,11 @@ func (p *program) Stop() error {
9596 return nil
9697}
9798
99+ // Context returns a context that will be canceled when nsqd initiates the shutdown
100+ func (p program ) Context () context.Context {
101+ return p .nsqd .Context ()
102+ }
103+
98104func logFatal (f string , args ... interface {}) {
99105 lg .LogFatal ("[nsqd] " , f , args ... )
100106}
Original file line number Diff line number Diff line change 11package nsqd
22
33import (
4+ "context"
45 "crypto/tls"
56 "crypto/x509"
67 "encoding/json"
@@ -46,6 +47,8 @@ type NSQD struct {
4647 clientIDSequence int64
4748
4849 sync.RWMutex
50+ ctx context.Context
51+ ctxCancel context.CancelFunc
4952
5053 opts atomic.Value
5154
@@ -99,6 +102,7 @@ func New(opts *Options) (*NSQD, error) {
99102 optsNotificationChan : make (chan struct {}, 1 ),
100103 dl : dirlock .New (dataPath ),
101104 }
105+ n .ctx , n .ctxCancel = context .WithCancel (context .Background ())
102106 httpcli := http_api .NewClient (nil , opts .HTTPClientConnectTimeout , opts .HTTPClientRequestTimeout )
103107 n .ci = clusterinfo .New (n .logf , httpcli )
104108
@@ -786,3 +790,8 @@ func buildTLSConfig(opts *Options) (*tls.Config, error) {
786790func (n * NSQD ) IsAuthEnabled () bool {
787791 return len (n .getOpts ().AuthHTTPAddresses ) != 0
788792}
793+
794+ // Context returns a context that will be canceled when nsqd initiates the shutdown
795+ func (n * NSQD ) Context () context.Context {
796+ return n .ctx
797+ }
You can’t perform that action at this time.
0 commit comments