Skip to content

Commit

Permalink
update simpleble (#671)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Parfenov <a1994ndrey@gmail.com>
  • Loading branch information
Andrey1994 committed Sep 7, 2023
1 parent 8552bbe commit a36a42f
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@
} \
} while (0)

#define WAIT_UNTIL_FALSE_WITH_TIMEOUT(obj, var, timeout) \
do { \
BOOL _tmpVar = YES; \
NSDate* endDate = [NSDate dateWithTimeInterval:timeout sinceDate:NSDate.now]; \
while (_tmpVar && [NSDate.now compare:endDate] == NSOrderedAscending) { \
[NSThread sleepForTimeInterval:0.01]; \
@synchronized(obj) { \
_tmpVar = (var); \
} \
} \
} while (0)

// --------------------------------------------------

@interface BleTask : NSObject
Expand Down Expand Up @@ -134,7 +146,7 @@ - (void)connect {
[self.centralManager connectPeripheral:self.peripheral options:@{}]; // TODO: Do we need to pass any options?
}

WAIT_UNTIL_FALSE(self, _task.pending);
WAIT_UNTIL_FALSE_WITH_TIMEOUT(self, _task.pending, 5.0);

if (self.peripheral.state != CBPeripheralStateConnected || _task.error != nil) {
[self throwBasedOnError:_task.error withFormat:@"Peripheral Connection"];
Expand Down

0 comments on commit a36a42f

Please sign in to comment.