4 ms·
Another possibility, if it's a matter of passing callback parameter that must be sync where you wish it could be an async function, is that the callback can be
by quietbritishjim 4y ago
Another possibility, if it's a matter of passing callback parameter that must be sync where you wish it could be an async function, is that the callback can be the `put_nowait()` method of an async queue. You can then have a background async task that pulls from that queue and does async stuff.
This works well if the callback is just there to notify you about a result (which is the most common case in fairness) but doesn't really work if the callback is meant to synchronously determine and return a result that is then used within the function that's calling the callback.
- gpderetta 4y agoYes, been there done that :). You can spawn a whole background thread running its own event loop, and post the async function with run-coroutine_threadsafe, the wait on the returned concurrent.future. But it feels wrong having to spawn a thread and event loop just for that.