Struct rustygear::client::ClientJob

source ·
pub struct ClientJob { /* private fields */ }
Expand description

Return object for submit_ functions.

Implementations§

source§

impl ClientJob

source

pub fn handle(&self) -> &ServerHandle

returns the job handle

Examples found in repository?
examples/multiserver.rs (line 26)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    env_logger::init();
    let mut client = Client::new()
        .add_server("127.0.0.1:4730")
        .add_server("127.0.0.1:4731")
        .connect()
        .await?;
    println!("Connected!");
    println!("Echo: {:?}", client.echo(b"blah").await);
    let mut jobs = Vec::new();
    for x in 0..10 {
        let payload = format!("payload{}", x);
        jobs.push(client.submit("reverse", payload.as_bytes()).await?);
    }
    println!(
        "Submitted {}",
        jobs.iter().map(|j| format!("{}", j)).collect::<String>()
    );
    for job in jobs.iter_mut() {
        let response = job.response().await;
        println!("Response for [{:?}] is [{:?}]", job.handle(), response)
    }
    Ok(())
}
More examples
Hide additional examples
examples/client.rs (line 13)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    env_logger::init();
    let server = "127.0.0.1:4730";
    let mut client = Client::new().add_server(server).connect().await?;
    println!("Connected!");
    println!("Echo: {:?}", client.echo(b"blah").await);
    let job = client.submit_background("reverse", b"abcdefg").await?;
    println!("Submitted {:?}", job.handle());
    let status = client.get_status(job.handle()).await?;
    println!("Status {:?}", status);
    let mut job = client.submit("reverse", b"bloop").await?;
    println!("Submitted {:?}", job.handle());
    let response = job.response().await?;
    println!("Got Back {:?}", response);
    let mut job = client.submit_unique("reverse", b"bloop1", b"bloop").await?;
    println!("Submitted unique {:?}", job.handle());
    let response = job.response().await?;
    println!("Got Back {:?}", response);
    Ok(())
}
source

pub async fn response(&mut self) -> Result<WorkUpdate, Error>

Should only return when the worker has sent data or completed the job.

Use this in clients to wait for a response on a job that was submitted. This will return an error if used on a background job.

Examples found in repository?
examples/multiserver.rs (line 25)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    env_logger::init();
    let mut client = Client::new()
        .add_server("127.0.0.1:4730")
        .add_server("127.0.0.1:4731")
        .connect()
        .await?;
    println!("Connected!");
    println!("Echo: {:?}", client.echo(b"blah").await);
    let mut jobs = Vec::new();
    for x in 0..10 {
        let payload = format!("payload{}", x);
        jobs.push(client.submit("reverse", payload.as_bytes()).await?);
    }
    println!(
        "Submitted {}",
        jobs.iter().map(|j| format!("{}", j)).collect::<String>()
    );
    for job in jobs.iter_mut() {
        let response = job.response().await;
        println!("Response for [{:?}] is [{:?}]", job.handle(), response)
    }
    Ok(())
}
More examples
Hide additional examples
examples/client.rs (line 18)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    env_logger::init();
    let server = "127.0.0.1:4730";
    let mut client = Client::new().add_server(server).connect().await?;
    println!("Connected!");
    println!("Echo: {:?}", client.echo(b"blah").await);
    let job = client.submit_background("reverse", b"abcdefg").await?;
    println!("Submitted {:?}", job.handle());
    let status = client.get_status(job.handle()).await?;
    println!("Status {:?}", status);
    let mut job = client.submit("reverse", b"bloop").await?;
    println!("Submitted {:?}", job.handle());
    let response = job.response().await?;
    println!("Got Back {:?}", response);
    let mut job = client.submit_unique("reverse", b"bloop1", b"bloop").await?;
    println!("Submitted unique {:?}", job.handle());
    let response = job.response().await?;
    println!("Got Back {:?}", response);
    Ok(())
}

Trait Implementations§

source§

impl Debug for ClientJob

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for ClientJob

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more