Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def fut(self):
p = qi.Promise()
#p.setValue(42)
threading.Thread(target=makeIt, args=[p]).start()
return p.future()
def wait_for(self, event, subscribe=False):
"""Block until a certain event is raised, and returns it's value.
If you pass subscribe=True, ALMemory.subscribeToEvent will be called
(sometimes necessary for side effects, i.e. WordRecognized).
This will block a thread so you should avoid doing this too often!
"""
if self.wait_promise:
# there was already a wait in progress, cancel it!
self.wait_promise.setCanceled()
self.wait_promise = qi.Promise()
if subscribe:
connection_id = self.subscribe(event, "EVENTHELPER",
self._on_wait_event)
elif "." in event: # it's a signal
connection_id = self.connect(event, self._on_wait_signal)
else:
connection_id = self.connect(event, self._on_wait_event)
try:
result = self.wait_promise.future().value()
finally:
self.disconnect(event, connection_id)
return result
def __init__(self):
self.running = True
self.promise = qi.Promise(self._on_future_cancelled)
self.future = self.promise.future()
self._exception = ""
self.lock = threading.Lock()