Top Description Fields Constructors Methods
io.reactivex.rxjava3.internal.subscriptions

public final Class AsyncSubscription

extends AtomicLong
implements Subscription, Disposable
Class Inheritance
All Implemented Interfaces
io.reactivex.rxjava3.disposables.Disposable, org.reactivestreams.Subscription
Imports
java.util.concurrent.atomic.*, org.reactivestreams.Subscription, io.reactivex.rxjava3.disposables.Disposable, io.reactivex.rxjava3.internal.disposables.DisposableHelper

A subscription implementation that arbitrates exactly one other Subscription and can hold a single disposable resource.

All methods are thread-safe.

Field Summary

Modifier and TypeField and Description
pack-priv final AtomicReference<Subscription>
pack-priv final AtomicReference<Disposable>
private static final long

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public void
cancel()

Implements org.reactivestreams.Subscription.cancel.

Request the Publisher to stop sending data and clean up resources.
public void
dispose()

Implements io.reactivex.rxjava3.disposables.Disposable.dispose.

Dispose the resource, the operation should be idempotent.
public boolean
isDisposed()

Implements io.reactivex.rxjava3.disposables.Disposable.isDisposed.

Returns true if this resource has been disposed.
public boolean

Returns:

false if this AsyncSubscription has been cancelled/disposed
replaceResource
(Disposable
the new resource to set
r
)

Replaces the currently held resource with the given new one without disposing the old.

public void
request(long
the strictly positive number of elements to requests to the upstream Publisher
n
)

Implements org.reactivestreams.Subscription.request.

No events will be sent by a Publisher until demand is signaled via this method.
public boolean

Returns:

false if this AsyncSubscription has been cancelled/disposed
setResource
(Disposable
the new resource to set
r
)

Sets a new resource and disposes the currently held resource.

public void
setSubscription(Subscription
the first and only subscription to set
s
)

Sets the given subscription if there isn't any subscription held.

Inherited from java.util.concurrent.atomic.AtomicLong:
accumulateAndGetaddAndGetcompareAndExchangecompareAndExchangeAcquirecompareAndExchangeReleasecompareAndSetdecrementAndGetdoubleValuefloatValuegetgetAcquiregetAndAccumulategetAndAddgetAndDecrementgetAndIncrementgetAndSetgetAndUpdategetOpaquegetPlainincrementAndGetintValuelazySetlongValuesetsetOpaquesetPlainsetReleasetoStringupdateAndGetweakCompareAndSetweakCompareAndSetAcquireweakCompareAndSetPlainweakCompareAndSetReleaseweakCompareAndSetVolatile

Field Detail

actualback to summary
pack-priv final AtomicReference<Subscription> actual
resourceback to summary
pack-priv final AtomicReference<Disposable> resource
serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.util.concurrent.atomic.AtomicLong.serialVersionUID.

Constructor Detail

AsyncSubscriptionback to summary
public AsyncSubscription()
AsyncSubscriptionback to summary
public AsyncSubscription(Disposable resource)

Method Detail

cancelback to summary
public void cancel()

Implements org.reactivestreams.Subscription.cancel.

Doc from org.reactivestreams.Subscription.cancel.

Request the Publisher to stop sending data and clean up resources.

Data may still be sent to meet previously signalled demand after calling cancel.

Annotations
@Override
disposeback to summary
public void dispose()

Implements io.reactivex.rxjava3.disposables.Disposable.dispose.

Doc from io.reactivex.rxjava3.disposables.Disposable.dispose.

Dispose the resource, the operation should be idempotent.

Annotations
@Override
isDisposedback to summary
public boolean isDisposed()

Implements io.reactivex.rxjava3.disposables.Disposable.isDisposed.

Doc from io.reactivex.rxjava3.disposables.Disposable.isDisposed.

Returns true if this resource has been disposed.

Returns:boolean

true if this resource has been disposed

Annotations
@Override
replaceResourceback to summary
public boolean replaceResource(Disposable r)

Replaces the currently held resource with the given new one without disposing the old.

Parameters
r:Disposable

the new resource to set

Returns:boolean

false if this AsyncSubscription has been cancelled/disposed

requestback to summary
public void request(long n)

Implements org.reactivestreams.Subscription.request.

Doc from org.reactivestreams.Subscription.request.

No events will be sent by a Publisher until demand is signaled via this method.

It can be called however often and whenever needed—but if the outstanding cumulative demand ever becomes Long.MAX_VALUE or more, it may be treated by the Publisher as "effectively unbounded".

Whatever has been requested can be sent by the Publisher so only signal demand for what can be safely handled.

A Publisher can send less than is requested if the stream ends but then must emit either Subscriber#onError(Throwable) or Subscriber#onComplete().

Parameters
n:long

the strictly positive number of elements to requests to the upstream Publisher

Annotations
@Override
setResourceback to summary
public boolean setResource(Disposable r)

Sets a new resource and disposes the currently held resource.

Parameters
r:Disposable

the new resource to set

Returns:boolean

false if this AsyncSubscription has been cancelled/disposed

See Also
replaceResource(Disposable)
setSubscriptionback to summary
public void setSubscription(Subscription s)

Sets the given subscription if there isn't any subscription held.

Parameters
s:Subscription

the first and only subscription to set