Esempio n. 1
0
    def wait(self):
        """Wait for this future's task to complete.

        This future will be done and will have either a result or an exception
        after a call to this method.
        """
        while not self._done:
            _eventloop.run1()
Esempio n. 2
0
    def result(self):
        """Return the result of this future's task.

        If the task is finished, this will return immediately. Otherwise, this
        will block until a result is ready.

        Returns:
            Any: The result
        """
        while not self._done:
            _eventloop.run1()

        return self._result
Esempio n. 3
0
def wait_any(futures):
    """Wait for any of several futures to finish.

    Args:
        futures (typing.Sequence[Future]): The futures to wait on.

    Returns:
        Future: The first future to be found to have finished.
    """
    if not futures:
        return None

    while True:
        for future in futures:
            if future.done():
                return future

        _eventloop.run1()
Esempio n. 4
0
    def wait(self):
        """Wait for this future's task to complete.

        This future will be done and will have either a result or an exception
        after a call to this method.
        """
        while not self._done:
            if not _eventloop.run1():
                raise RuntimeError("Eventloop is exhausted with unfinished futures.")
Esempio n. 5
0
def wait_any(futures):
    """Wait for any of several futures to finish.

    Args:
        futures (typing.Sequence[Future]): The futures to wait on.

    Returns:
        Future: The first future to be found to have finished.
    """
    if not futures:
        return None

    while True:
        for future in futures:
            if future.done():
                return future

        if not _eventloop.run1():
            raise RuntimeError("Eventloop is exhausted with unfinished futures.")
Esempio n. 6
0
def test_run1(context):
    loop = mock.Mock(spec=("run", "run1"))
    with context.new(eventloop=loop).use():
        _eventloop.run1()
        loop.run1.assert_called_once_with()
def test_run1(EventLoop):
    EventLoop.return_value = loop = unittest.mock.Mock(spec=("run", "run1"))
    with _runstate.state_context(None):
        _eventloop.run1()
        loop.run1.assert_called_once_with()
Esempio n. 8
0
def test_run1():
    with pytest.raises(NotImplementedError):
        eventloop.run1()
Esempio n. 9
0
def test_run1(EventLoop):
    EventLoop.return_value = loop = unittest.mock.Mock(spec=("run", "run1"))
    with eventloop.async_context():
        eventloop.run1()
        loop.run1.assert_called_once_with()
Esempio n. 10
0
def test_run1(EventLoop):
    EventLoop.return_value = loop = unittest.mock.Mock(spec=("run", "run1"))
    with _runstate.ndb_context():
        _eventloop.run1()
        loop.run1.assert_called_once_with()