asgiref AsyncToSync explanation

Viewed 435
# https://github.com/django/asgiref/blob/master/asgiref/sync.py
class AsyncToSync:
    """
    Utility class which turns an awaitable that only works on the thread with
    the event loop into a synchronous callable that works in a subthread.

    If the call stack contains an async loop, the code runs there.
    Otherwise, the code runs in a new loop in a new thread.
    
    ###############  DON'T UNDERSTAND ####################
    Either way, this thread then pauses and waits to run any thread_sensitive
    code called from further down the call stack using SyncToAsync, before
    finally exiting once the async task returns.
    """

Can anyone help to explain the bolded text? thanks in advance!

0 Answers
Related