def run_callback_threadsafe(loop: AbstractEventLoop, callback: Callable, *args: Any) -> concurrent.futures.Future:
    'Submit a callback object to a given event loop.\n\n    Return a concurrent.futures.Future to access the result.\n\n    NOTE: This code references home-assistant.\n    '
    ident = loop.__dict__.get('_thread_ident')
    if ((ident is not None) and (ident == threading.get_ident())):
        raise RuntimeError('Cannot be called from within the event loop')
    future = concurrent.futures.Future()

    def run_callback() -> None:
        'Run callback and store result.'
        try:
            future.set_result(callback(*args))
        except Exception as exc:
            if future.set_running_or_notify_cancel():
                future.set_exception(exc)
            else:
                _LOGGER.warning('Exception on lost future: ', exc_info=True)
    loop.call_soon_threadsafe(run_callback)
    return future
Submit a callback object to a given event loop.

Return a concurrent.futures.Future to access the result.

NOTE: This code references home-assistant.
def run_callback_threadsafe(loop: AbstractEventLoop, callback: Callable, *args: Any) -> concurrent.futures.Future:
    'Submit a callback object to a given event loop.\n\n    Return a concurrent.futures.Future to access the result.\n\n    NOTE: This code references home-assistant.\n    '
    ident = loop.__dict__.get('_thread_ident')
    if ((ident is not None) and (ident == threading.get_ident())):
        raise RuntimeError('Cannot be called from within the event loop')
    future = concurrent.futures.Future()

    def run_callback() -> None:
        'Run callback and store result.'
        try:
            future.set_result(callback(*args))
        except Exception as exc:
            if future.set_running_or_notify_cancel():
                future.set_exception(exc)
            else:
                _LOGGER.warning('Exception on lost future: ', exc_info=True)
    loop.call_soon_threadsafe(run_callback)
    return future