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>
impl<T: Send + 'static> KafkaFuture<T>
Sourcepub fn completed_future(result: Result<T, Error>) -> Self
pub fn completed_future(result: Result<T, Error>) -> Self
Sourcepub fn get_with_timeout(
&self,
timeout: Duration,
) -> impl Future<Output = Result<T, Error>> + Send
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_errorif the wait timed out: Java’sjava.util.concurrent.TimeoutException, not the retriableorg.apache.kafka.common.errors.TimeoutException.- The error the underlying operation failed with.
Sourcepub fn is_done(&self) -> bool
pub fn is_done(&self) -> bool
Returns true if completed in any fashion: normally, exceptionally, or via cancellation.
Sourcepub fn all_of(futures: Vec<KafkaFuture<T>>) -> KafkaFuture<()>
pub fn all_of(futures: Vec<KafkaFuture<T>>) -> KafkaFuture<()>
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.
Sourcepub fn then_apply<R, F>(&self, function: F) -> KafkaFuture<R>
pub fn then_apply<R, F>(&self, function: F) -> KafkaFuture<R>
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 aBaseFunction_newvalue; 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.