Class RangePublisher
java.lang.Object
org.reactivestreams.example.unicast.RangePublisher
A synchronous implementation of the
Publisher
that can
be subscribed to multiple times and each individual subscription
will receive range of monotonically increasing integer values on demand.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class
A Subscription implementation that holds the current downstream requested amount and responds to the downstream's request() and cancel() calls. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionRangePublisher
(int start, int count) Constructs a RangePublisher instance with the given start and count values that yields a sequence of [start, start + count). -
Method Summary
Modifier and TypeMethodDescriptionvoid
subscribe
(Subscriber<? super Integer> subscriber) RequestPublisher
to start streaming data.
-
Field Details
-
start
final int startThe starting value of the range. -
count
final int countThe number of items to emit.
-
-
Constructor Details
-
RangePublisher
public RangePublisher(int start, int count) Constructs a RangePublisher instance with the given start and count values that yields a sequence of [start, start + count).- Parameters:
start
- the starting value of the rangecount
- the number of items to emit
-
-
Method Details
-
subscribe
Description copied from interface:Publisher
RequestPublisher
to start streaming data.This is a "factory method" and can be called multiple times, each time starting a new
Subscription
.Each
Subscription
will work for only a singleSubscriber
.A
Subscriber
should only subscribe once to a singlePublisher
.If the
Publisher
rejects the subscription attempt or otherwise fails it will signal the error viaSubscriber.onError(Throwable)
.- Specified by:
subscribe
in interfacePublisher<Integer>
- Parameters:
subscriber
- theSubscriber
that will consume signals from thisPublisher
-