Share via


SubmissionPublisher.Offer Method

Definition

Overloads

Offer(Object, IBiPredicate)

Publishes the given item, if possible, to each current subscriber by asynchronously invoking its Flow.Subscriber#onNext(Object) onNext method.

Offer(Object, Int64, TimeUnit, IBiPredicate)

Publishes the given item, if possible, to each current subscriber by asynchronously invoking its Flow.Subscriber#onNext(Object) onNext method, blocking while resources for any subscription are unavailable, up to the specified timeout or until the caller thread is interrupted, at which point the given handler (if non-null) is invoked, and if it returns true, retried once.

Offer(Object, IBiPredicate)

Publishes the given item, if possible, to each current subscriber by asynchronously invoking its Flow.Subscriber#onNext(Object) onNext method.

[Android.Runtime.Register("offer", "(Ljava/lang/Object;Ljava/util/function/BiPredicate;)I", "GetOffer_Ljava_lang_Object_Ljava_util_function_BiPredicate_Handler", ApiSince=33)]
public virtual int Offer (Java.Lang.Object? item, Java.Util.Functions.IBiPredicate? onDrop);
[<Android.Runtime.Register("offer", "(Ljava/lang/Object;Ljava/util/function/BiPredicate;)I", "GetOffer_Ljava_lang_Object_Ljava_util_function_BiPredicate_Handler", ApiSince=33)>]
abstract member Offer : Java.Lang.Object * Java.Util.Functions.IBiPredicate -> int
override this.Offer : Java.Lang.Object * Java.Util.Functions.IBiPredicate -> int

Parameters

item
Object

the (non-null) item to publish

onDrop
IBiPredicate

if non-null, the handler invoked upon a drop to a subscriber, with arguments of the subscriber and item; if it returns true, an offer is re-attempted (once)

Returns

if negative, the (negative) number of drops; otherwise an estimate of maximum lag

Attributes

Remarks

Publishes the given item, if possible, to each current subscriber by asynchronously invoking its Flow.Subscriber#onNext(Object) onNext method. The item may be dropped by one or more subscribers if resource limits are exceeded, in which case the given handler (if non-null) is invoked, and if it returns true, retried once. Other calls to methods in this class by other threads are blocked while the handler is invoked. Unless recovery is assured, options are usually limited to logging the error and/or issuing an Flow.Subscriber#onError(Throwable) onError signal to the subscriber.

This method returns a status indicator: If negative, it represents the (negative) number of drops (failed attempts to issue the item to a subscriber). Otherwise it is an estimate of the maximum lag (number of items submitted but not yet consumed) among all current subscribers. This value is at least one (accounting for this submitted item) if there are any subscribers, else zero.

If the Executor for this publisher throws a RejectedExecutionException (or any other RuntimeException or Error) when attempting to asynchronously notify subscribers, or the drop handler throws an exception when processing a dropped item, then this exception is rethrown.

Java documentation for java.util.concurrent.SubmissionPublisher.offer(T, java.util.function.BiPredicate<java.util.concurrent.Flow.Subscriber<? super T>, ? super T>).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Offer(Object, Int64, TimeUnit, IBiPredicate)

Publishes the given item, if possible, to each current subscriber by asynchronously invoking its Flow.Subscriber#onNext(Object) onNext method, blocking while resources for any subscription are unavailable, up to the specified timeout or until the caller thread is interrupted, at which point the given handler (if non-null) is invoked, and if it returns true, retried once.

[Android.Runtime.Register("offer", "(Ljava/lang/Object;JLjava/util/concurrent/TimeUnit;Ljava/util/function/BiPredicate;)I", "GetOffer_Ljava_lang_Object_JLjava_util_concurrent_TimeUnit_Ljava_util_function_BiPredicate_Handler", ApiSince=33)]
public virtual int Offer (Java.Lang.Object? item, long timeout, Java.Util.Concurrent.TimeUnit? unit, Java.Util.Functions.IBiPredicate? onDrop);
[<Android.Runtime.Register("offer", "(Ljava/lang/Object;JLjava/util/concurrent/TimeUnit;Ljava/util/function/BiPredicate;)I", "GetOffer_Ljava_lang_Object_JLjava_util_concurrent_TimeUnit_Ljava_util_function_BiPredicate_Handler", ApiSince=33)>]
abstract member Offer : Java.Lang.Object * int64 * Java.Util.Concurrent.TimeUnit * Java.Util.Functions.IBiPredicate -> int
override this.Offer : Java.Lang.Object * int64 * Java.Util.Concurrent.TimeUnit * Java.Util.Functions.IBiPredicate -> int

Parameters

item
Object

the (non-null) item to publish

timeout
Int64

how long to wait for resources for any subscriber before giving up, in units of unit

unit
TimeUnit

a TimeUnit determining how to interpret the timeout parameter

onDrop
IBiPredicate

if non-null, the handler invoked upon a drop to a subscriber, with arguments of the subscriber and item; if it returns true, an offer is re-attempted (once)

Returns

if negative, the (negative) number of drops; otherwise an estimate of maximum lag

Attributes

Remarks

Publishes the given item, if possible, to each current subscriber by asynchronously invoking its Flow.Subscriber#onNext(Object) onNext method, blocking while resources for any subscription are unavailable, up to the specified timeout or until the caller thread is interrupted, at which point the given handler (if non-null) is invoked, and if it returns true, retried once. (The drop handler may distinguish timeouts from interrupts by checking whether the current thread is interrupted.) Other calls to methods in this class by other threads are blocked while the handler is invoked. Unless recovery is assured, options are usually limited to logging the error and/or issuing an Flow.Subscriber#onError(Throwable) onError signal to the subscriber.

This method returns a status indicator: If negative, it represents the (negative) number of drops (failed attempts to issue the item to a subscriber). Otherwise it is an estimate of the maximum lag (number of items submitted but not yet consumed) among all current subscribers. This value is at least one (accounting for this submitted item) if there are any subscribers, else zero.

If the Executor for this publisher throws a RejectedExecutionException (or any other RuntimeException or Error) when attempting to asynchronously notify subscribers, or the drop handler throws an exception when processing a dropped item, then this exception is rethrown.

Java documentation for java.util.concurrent.SubmissionPublisher.offer(T, long, java.util.concurrent.TimeUnit, java.util.function.BiPredicate<java.util.concurrent.Flow.Subscriber<? super T>, ? super T>).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to