How to use the qi.Promise function in qi

To help you get started, we’ve selected a few qi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aldebaran / libqi / python / examples / qiservice.py View on Github external
def fut(self):
        p = qi.Promise()
        #p.setValue(42)
        threading.Thread(target=makeIt, args=[p]).start()
        return p.future()
github pepperhacking / studiotoolkit / python / stk / events.py View on Github external
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
github pepperhacking / studiotoolkit / python / stk / coroutines.py View on Github external
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()