#static imap session

3 messages · Page 1 of 1 (latest)

trim sand
#

Often the best way to solve these kinds of problems is the "actor pattern". You have one spawned task which contains the session/connection (so you don't need a Mutex), and it receives a request through a channel (like tokio::sync::mpsc) and then interacts with the server to fetch that email or whatever and replies through a oneshot channel it was given with the request, and then goes back to waiting for a request.

#

This way, if the stuff needs to be on a single thread, then spawn_local of the actor suffices.

#

And if it doesn't, then it still handles the problem of keeping straight the state of the mail client