Using RwLocks in a tokio threadpool can cause performance issues since one future on one thread can block other futures on other threads, when those other threads could potentially be doing other work.
I don't have a clean solution for this example project using tokio_threadpool::blocking because you need to put blocking inside a poll_fn which requires values moved into the PollFn be Clone, but part of what we need inside these blocking sections is the write-half of a TcpStream, which is not Clone.
My idea for a way around this is we have a stream that folds over some state, and other futures interact with that state by sending and receiving messages.
Using RwLocks in a tokio threadpool can cause performance issues since one future on one thread can block other futures on other threads, when those other threads could potentially be doing other work.
I don't have a clean solution for this example project using
tokio_threadpool::blockingbecause you need to put blocking inside apoll_fnwhich requires values moved into thePollFnbeClone, but part of what we need inside theseblockingsections is the write-half of aTcpStream, which is notClone.My idea for a way around this is we have a stream that folds over some state, and other futures interact with that state by sending and receiving messages.