Reactive Java
Flow.Subscription.request
Add positive delivery demand, saturating at Long.MAX_VALUE. Executed Java 21 fixture.
Formal Syntax & Structure
java syntaxjava
subscription.request(n)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, 4)) { publisher.subscribe(probe); publisher.submit(10); publisher.submit(20); publisher.submit(30); System.out.println(probe.values); probe.subscription.request(2); System.out.println(probe.values); probe.subscription.request(1); System.out.println(probe.values); } System.out.println(probe.complete); }}