The sync module provides a thread-safe way to interact with a connection. While SyncConnection is the primary object, it cannot be easily shared across threads. Instead, you should use SyncConnectionHandle, which is a Clone-able handle that allows you to perform asynchronous actions (like sending commands, uploading/downloading files, or disconnecting) from any thread.
To use it, call .get_handle() on your SyncConnection instance. The actual SyncConnection object should typically be moved into a background task (e.g., using tokio::spawn) and polled as a Stream to process incoming events.
// Typical pattern for using SyncConnection
let con: SyncConnection = Connection::build("localhost").connect().unwrap().into();
let mut handle = con.get_handle();
// Move the connection to a background task to process the stream
tokio::spawn(con.for_each(|item| async { /* handle SyncStreamItem */ }));
// Use the handle in the main thread or other tasks
handle.wait_until_connected().await.unwrap();