Use sync.Once here to instantiate the event handler
This commit is contained in:
parent
22c53c365a
commit
a4c68eed16
|
@ -23,7 +23,7 @@ var _ environment.ProcessEnvironment = (*Environment)(nil)
|
||||||
|
|
||||||
type Environment struct {
|
type Environment struct {
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
eventMu sync.Mutex
|
eventMu sync.Once
|
||||||
|
|
||||||
// The public identifier for this environment. In this case it is the Docker container
|
// The public identifier for this environment. In this case it is the Docker container
|
||||||
// name that will be used for all instances created under it.
|
// name that will be used for all instances created under it.
|
||||||
|
@ -90,13 +90,9 @@ func (e *Environment) IsAttached() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Environment) Events() *events.EventBus {
|
func (e *Environment) Events() *events.EventBus {
|
||||||
e.eventMu.Lock()
|
e.eventMu.Do(func() {
|
||||||
defer e.eventMu.Unlock()
|
|
||||||
|
|
||||||
if e.emitter == nil {
|
|
||||||
e.emitter = events.New()
|
e.emitter = events.New()
|
||||||
}
|
})
|
||||||
|
|
||||||
return e.emitter
|
return e.emitter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user