From 1d784354b65e8bfb08c47538f41390971acb6690 Mon Sep 17 00:00:00 2001 From: Jan Wachsmuth Date: Sat, 7 Sep 2024 23:51:06 +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 c2b823e..56a41cc 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.