fix race potentil race condition where listeners were not subscribed before events started being emmited
This commit is contained in:
parent
f4b1296aa2
commit
5584fba6e5
|
@ -11,13 +11,14 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AppEventListener(gcd *gothings.GrandCentralDispatcher) {
|
func AppEventListener(gcd *gothings.GrandCentralDispatcher, subscribed chan bool) {
|
||||||
q := event.NewEventQueue(1000)
|
q := event.NewEventQueue(1000)
|
||||||
the.AppBus.Subscribe(event.NewPeer, q.EventChannel)
|
the.AppBus.Subscribe(event.NewPeer, q.EventChannel)
|
||||||
the.AppBus.Subscribe(event.PeerError, q.EventChannel)
|
the.AppBus.Subscribe(event.PeerError, q.EventChannel)
|
||||||
the.AppBus.Subscribe(event.AppError, q.EventChannel)
|
the.AppBus.Subscribe(event.AppError, q.EventChannel)
|
||||||
the.AppBus.Subscribe(event.ACNStatus, q.EventChannel)
|
the.AppBus.Subscribe(event.ACNStatus, q.EventChannel)
|
||||||
the.AppBus.Subscribe(event.ReloadDone, q.EventChannel)
|
the.AppBus.Subscribe(event.ReloadDone, q.EventChannel)
|
||||||
|
subscribed <- true
|
||||||
|
|
||||||
for {
|
for {
|
||||||
e := q.Next()
|
e := q.Next()
|
||||||
|
@ -68,6 +69,11 @@ func AppEventListener(gcd *gothings.GrandCentralDispatcher) {
|
||||||
the.Peer = the.CwtchApp.GetPeer(onion)
|
the.Peer = the.CwtchApp.GetPeer(onion)
|
||||||
the.EventBus = the.CwtchApp.GetEventBus(onion)
|
the.EventBus = the.CwtchApp.GetEventBus(onion)
|
||||||
|
|
||||||
|
incSubscribed := make(chan bool)
|
||||||
|
go IncomingListener(&gcd.UIState, incSubscribed)
|
||||||
|
<-incSubscribed
|
||||||
|
go PresencePoller(&gcd.UIState)
|
||||||
|
|
||||||
gcd.UpdateMyProfile(the.Peer.GetProfile().Name, the.Peer.GetProfile().Onion, cwutil.RandomProfileImage(the.Peer.GetProfile().Onion))
|
gcd.UpdateMyProfile(the.Peer.GetProfile().Name, the.Peer.GetProfile().Onion, cwutil.RandomProfileImage(the.Peer.GetProfile().Onion))
|
||||||
if e.Data[event.Status] != "running" {
|
if e.Data[event.Status] != "running" {
|
||||||
the.CwtchApp.LaunchPeers()
|
the.CwtchApp.LaunchPeers()
|
||||||
|
@ -110,8 +116,6 @@ func AppEventListener(gcd *gothings.GrandCentralDispatcher) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
go IncomingListener(&gcd.UIState)
|
|
||||||
go PresencePoller(&gcd.UIState)
|
|
||||||
|
|
||||||
// load ui preferences
|
// load ui preferences
|
||||||
gcd.RequestSettings()
|
gcd.RequestSettings()
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func IncomingListener(uiState *gothings.InterfaceState) {
|
func IncomingListener(uiState *gothings.InterfaceState, subscribed chan bool) {
|
||||||
q := event.NewEventQueue(1000)
|
q := event.NewEventQueue(1000)
|
||||||
the.EventBus.Subscribe(event.NewMessageFromPeer, q.EventChannel)
|
the.EventBus.Subscribe(event.NewMessageFromPeer, q.EventChannel)
|
||||||
the.EventBus.Subscribe(event.NewMessageFromGroup, q.EventChannel)
|
the.EventBus.Subscribe(event.NewMessageFromGroup, q.EventChannel)
|
||||||
|
@ -21,6 +21,7 @@ func IncomingListener(uiState *gothings.InterfaceState) {
|
||||||
the.EventBus.Subscribe(event.JoinServer, q.EventChannel)
|
the.EventBus.Subscribe(event.JoinServer, q.EventChannel)
|
||||||
the.EventBus.Subscribe(event.ServerStateChange, q.EventChannel)
|
the.EventBus.Subscribe(event.ServerStateChange, q.EventChannel)
|
||||||
the.EventBus.Subscribe(event.PeerStateChange, q.EventChannel)
|
the.EventBus.Subscribe(event.PeerStateChange, q.EventChannel)
|
||||||
|
subscribed <- true
|
||||||
|
|
||||||
for {
|
for {
|
||||||
e := q.Next()
|
e := q.Next()
|
||||||
|
|
4
main.go
4
main.go
|
@ -229,7 +229,9 @@ func loadNetworkingAndFiles(gcd *gothings.GrandCentralDispatcher, service bool,
|
||||||
|
|
||||||
if !service {
|
if !service {
|
||||||
the.AppBus = the.CwtchApp.GetPrimaryBus()
|
the.AppBus = the.CwtchApp.GetPrimaryBus()
|
||||||
go characters.AppEventListener(gcd)
|
subscribed := make(chan bool)
|
||||||
|
go characters.AppEventListener(gcd, subscribed)
|
||||||
|
<-subscribed
|
||||||
}
|
}
|
||||||
|
|
||||||
if !service && !clientUI {
|
if !service && !clientUI {
|
||||||
|
|
Reference in New Issue