Question about threads and sessions pool
soywod opened this issue · comments
I try to develop an email synchronizer for Himalaya. So far I have all the logic. I have a function sync
that produces a Patch
:
pub enum Hunk {
CopyEmail(Id, Flags, Source, Target),
RemoveEmail(Id, Target),
AddFlag(Id, Flag, Target),
RemoveFlag(Id, Flag, Target),
}
type Patch = Vec<Hunk>;
What I try to achieve is to execute hunks in parallel, by batch. If I have 30 hunks, 3 chunks of 10 hunks are produces and each 10 chunks are execute in parallel.
My question: how can I possibly achieve this with rust-imap
? A session seems not thread safe by default (the compiler complains on mpsc::Sender<UnsolicitedResponse>
and mpsc::Receiver<UnsolicitedResponse>
), should I create a pool of 10 sessions and reuse them for every chunk?
Thank you for your help.
I was able to set up a pool but the result was slower than just opening new sessions, so I guess we can close.
Sorry it took me ages to get back to you on this! It's definitely a bit weird that UnsolicitedResponse
isn't Send
— that's worth investigating. If there's an easy fix, we should try to land that!
Feel free to reopen (even rename the issue) if you find it necessary. For now I init a session pool with 8 connections and store them in a Vec<Mutex<ImapSession>>
. When a fn requires a session it get the next available from the list.