Reactive Java
SubmissionPublisher.offer
Offer without waiting for buffer space and report drops. Executed Java 21 fixture.
Formal Syntax & Structure
java syntaxjava
publisher.offer(value, (s,v) -> false)Working Example
Example Snippetjava
import java.util.concurrent.Flow;import java.util.concurrent.SubmissionPublisher;import java.util.ArrayList;import java.util.List;public class Main { static class Probe implements Flow.Subscriber<Integer> { Flow.Subscription subscription; final List<Integer> values = new ArrayList<>(); Throwable error; boolean complete; public void onSubscribe(Flow.Subscription s) { subscription = s; } public void onNext(Integer n) { values.add(n); } public void onError(Throwable t) { error = t; } public void onComplete() { complete = true; } } public static void main(String[] args) { var probe = new Probe(); try (var publisher = new SubmissionPublisher<Integer>(Runnable::run, 2)) { publisher.subscribe(probe); publisher.offer(1, (s, v) -> false); publisher.offer(2, (s, v) -> false); int result = publisher.offer(3, (s, v) -> false); System.out.println(result < 0); probe.subscription.request(2); System.out.println(probe.values); } }}