Skip to main content

KafkaFuture

Struct KafkaFuture 

Source
pub struct KafkaFuture<T: Send + 'static> { /* private fields */ }
Expand description

A flexible future which supports call chaining and other asynchronous programming patterns.

§Translation notes

Java’s get(), get(timeout, unit) and isDone() come from Future<T>; here get and get_with_timeout are async. This type is also what Producer::send returns, where Java returns Future<RecordMetadata>. toCompletionStage is not translated.

Implementations§

Source§

impl<T: Send + 'static> KafkaFuture<T>

Source

pub fn completed_future(result: Result<T, Error>) -> Self
where T: Clone + Sync,

Returns a new KafkaFuture that is already completed with the given value.

§Arguments
  • result - the value, or the error the future fails with
§Translation notes

result may also be an error.

Source

pub fn get(&self) -> impl Future<Output = Result<T, Error>> + Send

Waits if necessary for this future to complete, and then returns its result.

§Returns

The future’s value.

§Errors

The error the underlying operation failed with.

Source

pub fn get_with_timeout( &self, timeout: Duration, ) -> impl Future<Output = Result<T, Error>> + Send

Waits if necessary for at most the given time for this future to complete, and then returns its result, if available.

§Arguments
  • timeout - the maximum time to wait
§Returns

The future’s value.

§Errors
  • Error::is_local_timeout_error if the wait timed out: Java’s java.util.concurrent.TimeoutException, not the retriable org.apache.kafka.common.errors.TimeoutException.
  • The error the underlying operation failed with.
Source

pub fn is_done(&self) -> bool

Returns true if completed in any fashion: normally, exceptionally, or via cancellation.

Source

pub fn all_of(futures: Vec<KafkaFuture<T>>) -> KafkaFuture<()>
where T: Clone + Sync,

Returns a new KafkaFuture that is completed when all the given futures have completed. If any future fails, the returned future returns its error. If multiple futures fail, which error gets returned is arbitrarily chosen.

§Arguments
  • futures - the futures to wait for
§Translation notes

Unlike Java’s variadic allOf, the futures share one type T. The error is the first failed future’s in futures.

Source

pub fn then_apply<R, F>(&self, function: F) -> KafkaFuture<R>
where T: Clone + Sync, R: Clone + Send + Sync + 'static, F: BaseFunction<T, R> + 'static,

Returns a new KafkaFuture that, when this future completes normally, is executed with this future’s result as the argument to the supplied function. The function may be invoked by the task that calls then_apply or it may be invoked by the task that completes the future.

§Arguments
  • function - a closure or a BaseFunction_new value; the module docs show how to write one
§Translation notes

An Err from function, or a panic in it, fails the returned future, as a Java throw does.

Trait Implementations§

Source§

impl<T: Send + 'static> Clone for KafkaFuture<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Send + 'static> Debug for KafkaFuture<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for KafkaFuture<T>

§

impl<T> !RefUnwindSafe for KafkaFuture<T>

§

impl<T> Send for KafkaFuture<T>

§

impl<T> Sync for KafkaFuture<T>

§

impl<T> Unpin for KafkaFuture<T>

§

impl<T> UnsafeUnpin for KafkaFuture<T>

§

impl<T> !UnwindSafe for KafkaFuture<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V