pub struct RawClient { /* private fields */ }Expand description
A lightweight cheaply clonable client for sending raw requests(SimpleX commands) and receiving raw responses(JSON objects).
You can use the client behind a shared reference, or you can clone it, in both cases the created futures will be indpenendent from each other.
Implementations§
Source§impl RawClient
impl RawClient
Sourcepub async fn send(&self, command: Command) -> Result<Response>
pub async fn send(&self, command: Command) -> Result<Response>
Send a raw SimpleX command and await its response.
The command is sent immediately and the returned future directly awaits the response from the worker thread.
Sourcepub async fn version(&self) -> Result<SimplexVersion, VersionError>
pub async fn version(&self) -> Result<SimplexVersion, VersionError>
Returns the version of the underlying SimpleX runtime.
Sourcepub fn disconnect(self) -> impl Future<Output = ()>
pub fn disconnect(self) -> impl Future<Output = ()>
Initiates a graceful shutdown and waits until the database is fully closed.
All futures that got scheduled before this call will still receive their responses. All
futures scheduled after this call(from cloned clients) will resolve immediately with
CallError::Failure.
If you don’t care about waiting for the graceful shutdown to complete you can just drop the future, the shutdown will still be triggered
let _ = client.disconnect();or use [tokio::time::timeout] to limit the wait time
tokio::time::timeout(Duration::from_secs(5), client.disconnect())
.await
.unwrap_or_default();§Racing with Self::send
Commands and the disconnect signal share the same FIFO channel. Whichever call enqueues
first is processed first: If disconnect enqueues before a concurrent send the send
future returns CallError::Failure and the command is guaranteed not to have been
executed, if send enqueues before disconnect - the command executes normally.
To guarantee ordering, await all send futures to completion before calling disconnect.