Ejemplo n.º 1
0
def _exec_listener_thread_safe(loop: AbstractEventLoop,
                               listener: ListenerCb[K], context: Context,
                               event_instance: K) -> "Future[None]":
    # Create an internal future to better control the listener result
    result_future: "Future[None]" = loop.create_future()
    listener_loop = retrieve_loop_from_listener(listener) or loop
    if loop is listener_loop:
        context.run(
            _exec_listener,
            loop,
            result_future.cancel,
            result_future.set_exception,
            result_future.set_result,
            listener,
            event_instance,
        )
    else:
        listener_loop.call_soon_threadsafe(
            context.run,
            _exec_listener,
            listener_loop,
            partial(loop.call_soon_threadsafe, result_future.cancel),
            partial(loop.call_soon_threadsafe, result_future.set_exception),
            partial(loop.call_soon_threadsafe, result_future.set_result),
            listener,
            event_instance,
        )

    return result_future
Ejemplo n.º 2
0
 def _run_in_thread(self, future: Awaitable[RetT], ctx: Context) -> RetT:
     loop = self._local.event_loop
     ret = ctx.run(loop.run_until_complete, future)
     return cast(RetT, ret)
Ejemplo n.º 3
0
 def _run_in_thread(self, future: Awaitable[RetT], ctx: Context) -> RetT:
     loop = self._local.event_loop
     ret = ctx.run(loop.run_until_complete, future)
     return cast(RetT, ret)