Job

Struct Job 

Source
pub struct Job<T> { /* private fields */ }
Expand description

Job.

An object that provides asynchronous response data, and it may be canceled before the underlying task was done.

thread unsafe

§Examples

use tsubakuro_rust_core::prelude::*;

async fn example(client: &SqlClient, transaction: &Transaction) -> Result<(), TgError> {
    let sql = "insert into tb values(1, 'abc')";
    let mut job = client.execute_async(transaction, sql).await?;

    let execute_result = job.take_for(std::time::Duration::from_secs(10)).await?;

    Ok(())
}

Implementations§

Source§

impl<T> Job<T>

Source

pub fn name(&self) -> &String

Get job name.

Source

pub fn set_default_timeout(&mut self, timeout: Duration)

Set default timeout.

Source

pub async fn wait(&mut self, timeout: Duration) -> Result<bool, TgError>

Wait for response.

§Returns
  • Ok(true) - Response received.
  • Ok(false) - Timed out.
§Examples
use tsubakuro_rust_core::prelude::*;

async fn example(mut job: Job<SqlExecuteResult>) -> Result<(), TgError> {
    let done = job.wait(std::time::Duration::from_secs(10)).await?;
    if done {
        let execute_result = job.take().await?;
    }

    Ok(())
}
Source

pub async fn is_done(&mut self) -> Result<bool, TgError>

Whether a response has been received.

§Returns
  • Ok(true) - Response received.
  • Ok(false) - No response received.
§Examples
use tsubakuro_rust_core::prelude::*;

async fn example(mut job: Job<SqlExecuteResult>) -> Result<(), TgError> {
    loop {
        let done = job.is_done().await?;
        if done {
            let execute_result = job.take().await?;
            break;
        }
    }

    Ok(())
}
Source

pub async fn take(&mut self) -> Result<T, TgError>

Retrieves the result value, or wait until response has been received.

You can only take once to retrieve the value.

§Examples
use tsubakuro_rust_core::prelude::*;

async fn example(mut job: Job<SqlExecuteResult>) -> Result<(), TgError> {
    let execute_result = job.take().await?;

    Ok(())
}
Source

pub async fn take_for(&mut self, timeout: Duration) -> Result<T, TgError>

Retrieves the result value, or wait until response has been received.

You can only take once to retrieve the value.

§Examples
use tsubakuro_rust_core::prelude::*;

async fn example(mut job: Job<SqlExecuteResult>) -> Result<(), TgError> {
    let execute_result = job.take_for(std::time::Duration::from_secs(10)).await?;

    Ok(())
}
Source

pub async fn take_if_ready(&mut self) -> Result<Option<T>, TgError>

Retrieves the result value if a response has been received.

You can only take once to retrieve the value.

§Returns
  • Ok(Some(value)) - result value
  • Ok(None) - No response received.
§Examples
use tsubakuro_rust_core::prelude::*;

async fn example(mut job: Job<SqlExecuteResult>) -> Result<(), TgError> {
    loop {
        if let Some(execute_result) = job.take_if_ready().await? {
            break;
        }
    }

    Ok(())
}
Source

pub async fn cancel(self) -> Result<bool, TgError>

Cancel job.

§Returns
  • Ok(true) - Response received.
  • Ok(false) - Timed out.

The response is not necessarily OPERATION_CANCELED. Depending on the timing, it may be a normal processing result.

§Examples
use tsubakuro_rust_core::prelude::*;

async fn example(mut job: Job<SqlExecuteResult>) -> Result<(), TgError> {
    job.cancel().await?;

    Ok(())
}
Source

pub async fn cancel_for(self, timeout: Duration) -> Result<bool, TgError>

Cancel job.

§Returns
  • Ok(true) - Response already received, or cancel already started.
  • Ok(false) - Timed out.

The response is not necessarily OPERATION_CANCELED. Depending on the timing, it may be a normal processing result.

Source

pub async fn cancel_async(self) -> Result<Option<CancelJob>, TgError>

Cancel job.

§Returns
  • Ok(Some(CancelJob)) - Cancellation started.
  • Ok(None) - Not canceled. (response already received, or cancel already started)
§Examples
use tsubakuro_rust_core::prelude::*;

async fn example(mut job: Job<SqlExecuteResult>) -> Result<(), TgError> {
    if let Some(mut cancel_job) = job.cancel_async().await? {
        cancel_job.wait(std::time::Duration::from_secs(10)).await?;
    }

    Ok(())
}
Source

pub async fn close(self) -> Result<(), TgError>

Disposes this resource.

If no response is received and no cancellation is made, then execute cancel.

Trait Implementations§

Source§

impl<T> Debug for Job<T>

Source§

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

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

impl<T> Drop for Job<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Job<T>

§

impl<T> !RefUnwindSafe for Job<T>

§

impl<T> Send for Job<T>

§

impl<T> !Sync for Job<T>

§

impl<T> Unpin for Job<T>

§

impl<T> !UnwindSafe for Job<T>

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, 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,