pub struct InvocationBuilder<'a> { /* private fields */ }Expand description
Request builder for the SignalRClient
Allows adding streams and arguments to the invocation. Contains set of method that drive behavior of response reception.
Implementations§
Source§impl<'a> InvocationBuilder<'a>
impl<'a> InvocationBuilder<'a>
Sourcepub fn arg<A, B>(self, arg: A) -> Result<Self, ClientError>
pub fn arg<A, B>(self, arg: A) -> Result<Self, ClientError>
Adds ordered argument to invocation
Argument can either be:
- a value
- a stream
Order of arguments matters, they need to be passed in exactly the same order server expects them.
§Example
Assuming server has a hub method defined as:
use futures::stream::Stream;
fn calculate(name: String, a: usize, b: usize, items: impl Stream<Item = usize>) -> usize {
println!("{}", name);
a + b
}Innvocation would have to be built in a following way to call this method
use signalrs_client::{SignalRClient, arguments::InvocationStream};
use futures::StreamExt;
let client: SignalRClient = get_client();
let result = client.method("calculate")
.arg("Johnny")?
.arg(1)?
.arg(2)?
.arg(InvocationStream::new(futures::stream::repeat(1usize).take(5)))?
.invoke::<usize>()
.await?;
Sourcepub async fn send(self) -> Result<(), ClientError>
pub async fn send(self) -> Result<(), ClientError>
Sends an invocation to the server and does not expect any response
This method follows ‘fire and forget’ semantics. As soon as the message is sent from the client it returns to the caller. Server then processes the request asynchronously.
Sourcepub async fn invoke_unit(self) -> Result<(), ClientError>
pub async fn invoke_unit(self) -> Result<(), ClientError>
Sends an ivocation to the server and awaits unit response
It does not expect any meaingful reponse except from empty response from the server.
It follows semantics such as void methods or functions returning ().
Sourcepub async fn invoke<T: DeserializeOwned>(self) -> Result<T, ClientError>
pub async fn invoke<T: DeserializeOwned>(self) -> Result<T, ClientError>
Sends an ivocation to the server and awaits meaningful, single response
It expects the response to be well-structured object in an encoding format used for communication.
For instance this method can return usize or MyCustomStruct as long as this type implements Deserialize and is not generic over lifetime.
§Important
This function will cause errors if called with (). Use invoke_unit to do this.
Sourcepub async fn invoke_stream<T: DeserializeOwned>(
self,
) -> Result<ResponseStream<'a, T>, ClientError>
pub async fn invoke_stream<T: DeserializeOwned>( self, ) -> Result<ResponseStream<'a, T>, ClientError>
Sends an ivocation to the server and awaits meaningful stream of responses
It expects the responses to be well-structured objects in an encoding format used for communication.
For instance this method can return a Stream of usize or MyCustomStruct as long as this type implements Deserialize and is not generic over lifetime.
§Example
Assuming server has a hub method defined as:
use futures::stream::Stream;
use futures::stream::StreamExt;
fn answers() -> impl Stream<Item = String> {
// not really important what happens here
}Innvocation would have to be built in a following way to call this method
use signalrs_client::{SignalRClient, arguments::InvocationStream};
use futures::StreamExt;
let client: SignalRClient = get_client();
let mut result = client.method("answers")
.invoke_stream::<String>().await?;
while let Some(answer) = result.next().await {
println!("next answer: {}", answer?);
}