From 3f74826c12684c483721a9ceae22218d3d58b852 Mon Sep 17 00:00:00 2001 From: Wilko Date: Thu, 22 Aug 2024 21:24:26 +0200 Subject: [PATCH] Resolve blocking channel --- gatt.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gatt.go b/gatt.go index ae8fcc00..53bf8c84 100644 --- a/gatt.go +++ b/gatt.go @@ -144,8 +144,17 @@ func Connect(ctx context.Context, f AdvFilter) (Client, error) { } } - cln, err := Dial(ctx, (<-ch).Addr()) - return cln, errors.Wrap(err, "can't dial") + select { + case a, ok := <-ch: + if ok { + cln, err := Dial(ctx, a.Addr()) + return cln, errors.Wrap(err, "can't dial") + } else { + return nil, errors.New("channel closed") + } + default: + return nil, errors.New("not found") + } } // A NotificationHandler handles notification or indication from a server.