pub struct RawClient { /* private fields */ }ffi only.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: String) -> Result<String, Arc<CallError>>
pub async fn send(&self, command: String) -> Result<String, Arc<CallError>>
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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RawClient
impl RefUnwindSafe for RawClient
impl Send for RawClient
impl Sync for RawClient
impl Unpin for RawClient
impl UnsafeUnpin for RawClient
impl UnwindSafe for RawClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more