pub struct RawClient { /* private fields */ }Expand description
A lightweight cheaply clonable client capable of 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<Response>
pub async fn send(&self, command: String) -> Result<Response>
Send a raw SimpleX request that is a SimpleX CLI command.
The actual request sending part always resolves immediately so the send(..).await call
directly awaits the response.
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 it is complete. Returns only after the connection 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
tungstenite::Error::AlreadyClosed.
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
If Self::send and Self::disconnect are called concurrently from different threads
the outcome depends on scheduling. If send wins the channel lock first, it will receive a
response as normal. If disconnect wins first, the send future will receive
tungstenite::Error::AlreadyClosed.
However, in the second case the request could have already been buffered and delivered to the
server by another thread while disconnect was executing on the current thread, meaning the
send command ran even though the client received an error. Do not use AlreadyClosed as a
proof that the command was not executed. To guarantee ordering, await all send futures to
completion before calling disconnect.