What's the correct way of limiting the Tokio (v 0.1.11) threadpool to n OS native threads, where n is an arbitrary number, preferably configurable at runtime?
As far as I can tell, it's possible to use Tokio in single threaded mode using using tokio_current_thread::block_on_all instead of tokio::run and tokio_current_thread::spawn instead of tokio::spawn.
I'd like a similar solution but for n >= 1.
You can build a Tokio
Runtimeobject usingtokio::runtime::Builder. The builder offers acore_threads()method that can be used to configure the number of threads, e.g.You can then use
rt.spawn(some_future)to run a future on this runtime.