netcan / asyncio

asyncio is a c++20 library to write concurrent code using the async/await syntax.
MIT License
812 stars 80 forks source link

Python: run_soon_threadsafe #16

Open 0lru opened 1 year ago

0lru commented 1 year ago

Nice Python-like-API-approach. I started something like this some time ago and my event loop class looked pretty much the same.

In Python, you can have multiple event loops: See https://docs.python.org/3/library/asyncio-eventloop.html call_soon_threadsafe, set_event_loop etc.

I think it's about making this a thread_local:

EventLoop& get_event_loop() {
    static EventLoop loop;
    return loop;
}

The continuation may be a bit different as well. I'd love a combination of this API with the multithreading-capabilities of https://github.com/David-Haim/concurrencpp.