refactoring. Created EventBus singleton.
This commit is contained in:
parent
0fd78b7533
commit
b344469caa
|
@ -17,7 +17,7 @@ type ClientChan chan string
|
||||||
// Get a reference to the EventBus singleton Start procnteessing requests
|
// Get a reference to the EventBus singleton Start procnteessing requests
|
||||||
// this should be a singleton, to ensure that we're always broadcasting to the same clients
|
// this should be a singleton, to ensure that we're always broadcasting to the same clients
|
||||||
// see: https://refactoring.guru/design-patterns/singleton/go/example
|
// see: https://refactoring.guru/design-patterns/singleton/go/example
|
||||||
func GetEventBusServer() (bus *EventBus) {
|
func GetEventBusServer() *EventBus {
|
||||||
if singletonEventBusInstance == nil {
|
if singletonEventBusInstance == nil {
|
||||||
eventBusLock.Lock()
|
eventBusLock.Lock()
|
||||||
defer eventBusLock.Unlock()
|
defer eventBusLock.Unlock()
|
||||||
|
@ -31,7 +31,7 @@ func GetEventBusServer() (bus *EventBus) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start processing requests
|
// Start processing requests
|
||||||
go bus.listen()
|
go singletonEventBusInstance.listen()
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Single instance already created.")
|
fmt.Println("Single instance already created.")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue