diff --git a/pc_ble_driver_py/ble_adapter.py b/pc_ble_driver_py/ble_adapter.py index ed339c11..79f7963c 100644 --- a/pc_ble_driver_py/ble_adapter.py +++ b/pc_ble_driver_py/ble_adapter.py @@ -146,19 +146,22 @@ def __repr__(self): class EvtSync(object): def __init__(self, events): self.conds = dict() + self.data = dict() for evt in events: self.conds[evt] = Condition(Lock()) - self.data = None + self.data[evt] = None def wait(self, evt, timeout=8): - self.data = None with self.conds[evt]: - self.conds[evt].wait(timeout=timeout) - return self.data + if self.data[evt] is None: + self.conds[evt].wait(timeout=timeout) + result = self.data[evt] + self.data[evt] = None + return result def notify(self, evt, data=None): with self.conds[evt]: - self.data = data + self.data[evt] = data self.conds[evt].notify_all()