예제 #1
0
    def __init__(
        self,
        sync_base: "SyncBase",
        event: str,
        predicate: Callable[[T], bool] = None,
        timeout: int = None,
    ) -> None:
        self._value: Optional[T] = None
        self._exception = None
        self._loop = sync_base._loop

        wait_helper = WaitHelper(sync_base._loop)
        wait_helper.reject_on_timeout(
            timeout or 30000, f'Timeout while waiting for event "${event}"')
        self._future = sync_base._loop.create_task(
            wait_helper.wait_for_event(sync_base._impl_obj, event, predicate))
        g_self = greenlet.getcurrent()

        def done_callback(task: Any) -> None:
            try:
                self._value = mapping.from_maybe_impl(self._future.result())
            except Exception as e:
                self._exception = e
            finally:
                g_self.switch()

        self._future.add_done_callback(done_callback)
 def __init__(
     self,
     channel_owner: ChannelOwner,
     event: str,
     predicate: Callable[[T], bool] = None,
     timeout: int = None,
 ) -> None:
     self._value: Optional[T] = None
     wait_helper = WaitHelper(channel_owner._loop)
     wait_helper.reject_on_timeout(
         timeout or 30000, f'Timeout while waiting for event "${event}"'
     )
     self._future = asyncio.get_event_loop().create_task(
         wait_helper.wait_for_event(channel_owner, event, predicate)
     )