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 1
1
package main
2
2
3
3
import (
4
+ "context"
4
5
"flag"
5
6
"fmt"
6
7
"math/rand"
@@ -95,6 +96,11 @@ func (p *program) Stop() error {
95
96
return nil
96
97
}
97
98
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
+
98
104
func logFatal (f string , args ... interface {}) {
99
105
lg .LogFatal ("[nsqd] " , f , args ... )
100
106
}
Original file line number Diff line number Diff line change 1
1
package nsqd
2
2
3
3
import (
4
+ "context"
4
5
"crypto/tls"
5
6
"crypto/x509"
6
7
"encoding/json"
@@ -46,6 +47,8 @@ type NSQD struct {
46
47
clientIDSequence int64
47
48
48
49
sync.RWMutex
50
+ ctx context.Context
51
+ ctxCancel context.CancelFunc
49
52
50
53
opts atomic.Value
51
54
@@ -99,6 +102,7 @@ func New(opts *Options) (*NSQD, error) {
99
102
optsNotificationChan : make (chan struct {}, 1 ),
100
103
dl : dirlock .New (dataPath ),
101
104
}
105
+ n .ctx , n .ctxCancel = context .WithCancel (context .Background ())
102
106
httpcli := http_api .NewClient (nil , opts .HTTPClientConnectTimeout , opts .HTTPClientRequestTimeout )
103
107
n .ci = clusterinfo .New (n .logf , httpcli )
104
108
@@ -786,3 +790,8 @@ func buildTLSConfig(opts *Options) (*tls.Config, error) {
786
790
func (n * NSQD ) IsAuthEnabled () bool {
787
791
return len (n .getOpts ().AuthHTTPAddresses ) != 0
788
792
}
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