Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions gap_darwin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bluetooth

import (
"context"
"errors"
"fmt"
"time"
Expand Down Expand Up @@ -104,6 +105,11 @@ type deviceInternal struct {

// Connect starts a connection attempt to the given peripheral device address.
func (a *Adapter) Connect(address Address, params ConnectionParams) (Device, error) {
return a.ConnectWithContext(context.Background(), address, params)
}

// ConnectWithContext starts a connection attempt to the given peripheral device address.
func (a *Adapter) ConnectWithContext(ctx context.Context, address Address, params ConnectionParams) (Device, error) {
uuid, err := cbgo.ParseUUID(address.UUID.String())
if err != nil {
return Device{}, err
Expand Down Expand Up @@ -162,6 +168,16 @@ func (a *Adapter) Connect(address Address, params ConnectionParams) (Device, err
// record an error to use when the disconnect comes through later.
connectionError = errors.New("timeout on Connect")

// we are not ready to return yet, we need to wait for the disconnect event to come through
// so continue on from this case and wait for something to show up on prphCh
continue
case <-ctx.Done():
// we need to cancel the connection if the context is done
a.cm.CancelConnect(prphs[0])

// record an error to use when the disconnect comes through later.
connectionError = ctx.Err()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only difference is the error retrieval, here. Maybe we can find a "clever" way to not duplicate code.


// we are not ready to return yet, we need to wait for the disconnect event to come through
// so continue on from this case and wait for something to show up on prphCh
continue
Expand Down
Loading