I have a library that spawns a bunch of tasks. The library is very lightweight; it opens only a few TCP connections and spends 99.9% of its time idle, so scaling is not important. The library works fine with both threadpool
and current_thread
runtimes, and I want to provide an API that works with both. For this I need to abstract over two things:
- spawn function to use:
tokio::spawn
ortokio::current_thread::spawn
- "shared mutable reference" type:
Arc<Mutex<..>>
orRc<RefCell<..>>
A simple generalization of both of these APIs (spawn functions and ref types) would mean adding Send
constraint to my API methods even though I don't need Send
when current_thread
runtime is used.
So I need something more sophisticated, but I'm not sure what. Any help would be appreciated.