File tree Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -43,16 +43,23 @@ func (a *Adapter) Enable() error {
4343 }
4444
4545 // wait until powered
46- a .poweredChan = make (chan error )
46+ a .poweredChan = make (chan error , 1 )
4747
4848 a .cmd = & centralManagerDelegate {a : a }
4949 a .cm .SetDelegate (a .cmd )
50- select {
51- case <- a .poweredChan :
52- case <- time .NewTimer (10 * time .Second ).C :
53- return errors .New ("timeout enabling CentralManager" )
50+
51+ if a .cm .State () != cbgo .ManagerStatePoweredOn {
52+ select {
53+ case <- a .poweredChan :
54+ case <- time .NewTimer (10 * time .Second ).C :
55+ return errors .New ("timeout enabling CentralManager" )
56+ }
57+ }
58+
59+ // drain any extra powered-on events from channel
60+ for len (a .poweredChan ) > 0 {
61+ <- a .poweredChan
5462 }
55- a .poweredChan = nil
5663
5764 // wait until powered?
5865 a .pmd = & peripheralManagerDelegate {a : a }
@@ -73,7 +80,7 @@ type centralManagerDelegate struct {
7380func (cmd * centralManagerDelegate ) CentralManagerDidUpdateState (cmgr cbgo.CentralManager ) {
7481 // powered on?
7582 if cmgr .State () == cbgo .ManagerStatePoweredOn {
76- close ( cmd .a .poweredChan )
83+ cmd .a .poweredChan <- nil
7784 }
7885
7986 // TODO: handle other state changes.
You can’t perform that action at this time.
0 commit comments