Class ConcurrentSubscription
java.lang.Object
io.servicetalk.concurrent.internal.ConcurrentSubscription
- All Implemented Interfaces:
Cancellable
,PublisherSource.Subscription
This class prevents concurrent invocation of
PublisherSource.Subscription
methods and preserves the
Reactive Streams, 2.7
rule when there is a possibility of concurrency.-
Field Summary
Fields inherited from interface io.servicetalk.concurrent.Cancellable
IGNORE_CANCEL
-
Constructor Summary
ModifierConstructorDescriptionprotected
ConcurrentSubscription
(PublisherSource.Subscription subscription) New instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
cancel()
Sends a hint to the producer of the associated asynchronous execution that the consumer related to thisCancellable
is not interested in the outcome of the execution.void
request
(long n) Requestsn
more items from the associatedPublisherSource
for the associatedPublisherSource.Subscriber
.static ConcurrentSubscription
wrap
(PublisherSource.Subscription subscription) Wrap aPublisherSource.Subscription
to make it thread safe when concurrent access may exists betweenPublisherSource.Subscription.request(long)
andCancellable.cancel()
.
-
Constructor Details
-
ConcurrentSubscription
New instance.- Parameters:
subscription
-PublisherSource.Subscription
to wrap.
-
-
Method Details
-
wrap
Wrap aPublisherSource.Subscription
to make it thread safe when concurrent access may exists betweenPublisherSource.Subscription.request(long)
andCancellable.cancel()
.- Parameters:
subscription
- The subscription to wrap.- Returns:
- A
PublisherSource.Subscription
that will enforce the threading constraints in a concurrent environment.
-
request
public void request(long n) Description copied from interface:PublisherSource.Subscription
Requestsn
more items from the associatedPublisherSource
for the associatedPublisherSource.Subscriber
.See Reactive Streams specifications for the rules about how and when this method will be invoked.
- Specified by:
request
in interfacePublisherSource.Subscription
- Parameters:
n
- Number of items to request.
-
cancel
public void cancel()Description copied from interface:Cancellable
Sends a hint to the producer of the associated asynchronous execution that the consumer related to thisCancellable
is not interested in the outcome of the execution.- Specified by:
cancel
in interfaceCancellable
-