8 lines
297 B
Python
8 lines
297 B
Python
import asyncio
|
|
|
|
def wrap_async(coro_func):
|
|
"""Wraps an async callback to be safely called from another thread."""
|
|
loop = asyncio.get_event_loop()
|
|
def wrapper(*args, **kwargs):
|
|
loop.call_soon_threadsafe(lambda: asyncio.create_task(coro_func(*args, **kwargs)))
|
|
return wrapper |