commit
53554d98cd
27
service.go
27
service.go
@ -3,6 +3,7 @@ package micro
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -15,7 +16,7 @@ import (
|
|||||||
type service struct {
|
type service struct {
|
||||||
opts Options
|
opts Options
|
||||||
|
|
||||||
init chan bool
|
once sync.Once
|
||||||
}
|
}
|
||||||
|
|
||||||
func newService(opts ...Option) Service {
|
func newService(opts ...Option) Service {
|
||||||
@ -30,7 +31,6 @@ func newService(opts ...Option) Service {
|
|||||||
|
|
||||||
return &service{
|
return &service{
|
||||||
opts: options,
|
opts: options,
|
||||||
init: make(chan bool),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,23 +56,12 @@ func (s *service) run(exit chan bool) {
|
|||||||
// which parses command line flags. cmd.Init is only called
|
// which parses command line flags. cmd.Init is only called
|
||||||
// on first Init.
|
// on first Init.
|
||||||
func (s *service) Init(opts ...Option) {
|
func (s *service) Init(opts ...Option) {
|
||||||
// If <-s.init blocks, Init has not been called yet
|
// process options
|
||||||
// so we can call cmd.Init once.
|
for _, o := range opts {
|
||||||
select {
|
o(&s.opts)
|
||||||
case <-s.init:
|
}
|
||||||
// only process options
|
|
||||||
for _, o := range opts {
|
|
||||||
o(&s.opts)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
// close init
|
|
||||||
close(s.init)
|
|
||||||
|
|
||||||
// process options
|
|
||||||
for _, o := range opts {
|
|
||||||
o(&s.opts)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
s.once.Do(func() {
|
||||||
// Initialise the command flags, overriding new service
|
// Initialise the command flags, overriding new service
|
||||||
s.opts.Cmd.Init(
|
s.opts.Cmd.Init(
|
||||||
cmd.Broker(&s.opts.Broker),
|
cmd.Broker(&s.opts.Broker),
|
||||||
@ -81,7 +70,7 @@ func (s *service) Init(opts ...Option) {
|
|||||||
cmd.Client(&s.opts.Client),
|
cmd.Client(&s.opts.Client),
|
||||||
cmd.Server(&s.opts.Server),
|
cmd.Server(&s.opts.Server),
|
||||||
)
|
)
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) Options() Options {
|
func (s *service) Options() Options {
|
||||||
|
Loading…
Reference in New Issue
Block a user