goble
goble copied to clipboard
emitter.go:
emitter.go
- Added a MakeEmitter func that will create an Emitter and initialized its properties.
- Added Close func to clean chans of Emitter
- Added chan for subscribe and for clean
- Subscribe: The On function of Emitter now write on chan Subscribe
- Clean: The Close func (just added) write on the clean chan
- Updated Init func
- There is a Select statement inside the loop. The cases of the select are
- event: in order to propagte event received from xpc to user handlers
- subscribe(just added): in order to add an handler to the map of handlers
- clean(just added): in order to clean up all channels an quit the loop
- comment the close at the end of the lopp that maked it panic
- removed each break based on result. The bool returned by the handlers are not used anymore (keep for retrocompatibility issues)
- There is a Select statement inside the loop. The cases of the select are
goble.go
- Call ble.Emitter.Init() inside func (ble *BLE) Init() instead of New
- sendCBMsg: use the message constructed instead of rebuilted it
- HandleXpcEvent: In the read case, use
Get
instead ofMust
because when connected to a peripheral after a connect. Automatically received a read event that does not contained- kCBMsgArgCharacteristicHandle
- kCBMsgArgData
Can you explain why you added the emitter callbacks ?
Also, this PR contains some unrelated fixes (sendCBMsg and HandleXpcEvent) that should be sent separately (maybe with an associated issue ?)
Thanks!
Hi,
I made some changes since then. I can commit them if you want. The first purpose of this PR was to handle the panic when closing the channel in the Emitter.Init(). I added the chan subscribing to handle the subscription of the Emitter callback. This way you won't have concurrent problems on handlers. Writing in the handler array is done in the same goroutine than the read.
Best