Package autodispose2

AutoDispose is an RxJava 2 tool for automatically binding the execution of RxJava 2 streams to a provided scope via disposal/cancellation.

The idea is simple: construct your chain like any other, and then at subscription you simply drop in the relevant factory call + method for that type as a converter. In everyday use, it usually looks like this:

 myObservable .doStuff() .to(autoDisposable(this)) // <-- AutoDispose .subscribe(s -> ...); 

By doing this, you will automatically unsubscribe from myObservable as indicated by your scope - this helps prevent many classes of errors when an observable emits and item, but the actions taken in the subscription are no longer valid. For instance, if a network request comes back after a UI has already been torn down, the UI can't be updated - this pattern prevents this type of bug.

Types

AutoDispose
Link copied to clipboard
class AutoDispose
Factories for autodispose converters that can be used with RxJava types' corresponding {@code * as(...)} methods to transform them into auto-disposing streams.
AutoDisposeContext
Link copied to clipboard
interface AutoDisposeContext
A context intended for use as AutoDisposeContext.() -> Unit function body parameters where zero-arg autoDispose functions can be called.
AutoDisposeConverter
Link copied to clipboard
interface AutoDisposeConverter<@NonNull() T> : FlowableConverter<T, FlowableSubscribeProxy<T>> , ParallelFlowableConverter<T, ParallelFlowableSubscribeProxy<T>> , ObservableConverter<T, ObservableSubscribeProxy<T>> , MaybeConverter<T, MaybeSubscribeProxy<T>> , SingleConverter<T, SingleSubscribeProxy<T>> , CompletableConverter<CompletableSubscribeProxy>
A custom converter that implements all the RxJava types converters, for use with the {@code as()} operator.
AutoDisposePlugins
Link copied to clipboard
class AutoDisposePlugins
Utility class to inject handlers to certain standard autodispose-lifecycle operations.
CompletableSubscribeProxy
Link copied to clipboard
interface CompletableSubscribeProxy
Subscribe proxy that matches Completable's subscribe overloads.
FlowableSubscribeProxy
Link copied to clipboard
interface FlowableSubscribeProxy<@NonNull() T>
Subscribe proxy that matches Flowable's subscribe overloads.
MaybeSubscribeProxy
Link copied to clipboard
interface MaybeSubscribeProxy<@NonNull() T>
Subscribe proxy that matches Maybe's subscribe overloads.
ObservableSubscribeProxy
Link copied to clipboard
interface ObservableSubscribeProxy<@NonNull() T>
Subscribe proxy that matches Observable's subscribe overloads.
OutsideScopeException
Link copied to clipboard
open class OutsideScopeException : RuntimeException
Signifies an error occurred due to execution starting outside the lifecycle.
ParallelFlowableSubscribeProxy
Link copied to clipboard
interface ParallelFlowableSubscribeProxy<@NonNull() T>
Subscribe proxy that matches ParallelFlowable's subscribe overloads.
ScopeProvider
Link copied to clipboard
@DoNotMock(value = Use TestScopeProvider instead)
interface ScopeProvider
Provides a CompletableSource representation of a scope.
Scopes
Link copied to clipboard
class Scopes
Utilities for dealing with AutoDispose scopes.
SingleSubscribeProxy
Link copied to clipboard
interface SingleSubscribeProxy<@NonNull() T>
Subscribe proxy that matches Single's subscribe overloads.
TestScopeProvider
Link copied to clipboard
class TestScopeProvider : ScopeProvider
ScopeProvider implementation for testing.

Functions

autoDispose
Link copied to clipboard
@CheckReturnValue()
inline fun Completable.autoDispose(provider: ScopeProvider): CompletableSubscribeProxy
Extension that proxies to Completable.as + AutoDispose.autoDisposable
@CheckReturnValue()
inline fun Completable.autoDispose(scope: Completable): CompletableSubscribeProxy
Extension that proxies to Completable.as + AutoDispose.autoDisposable
@CheckReturnValue()
inline fun <T : Any> Flowable<T>.autoDispose(provider: ScopeProvider): FlowableSubscribeProxy<T>
Extension that proxies to Flowable.as + AutoDispose.autoDisposable
@CheckReturnValue()
inline fun <T : Any> Flowable<T>.autoDispose(scope: Completable): FlowableSubscribeProxy<T>
Extension that proxies to Flowable.as + AutoDispose.autoDisposable
@CheckReturnValue()
inline fun <T : Any> Maybe<T>.autoDispose(provider: ScopeProvider): MaybeSubscribeProxy<T>
Extension that proxies to Maybe.as + AutoDispose.autoDisposable
@CheckReturnValue()
inline fun <T : Any> Maybe<T>.autoDispose(scope: Completable): MaybeSubscribeProxy<T>
Extension that proxies to Maybe.as + AutoDispose.autoDisposable
@CheckReturnValue()
inline fun <T : Any> Observable<T>.autoDispose(provider: ScopeProvider): ObservableSubscribeProxy<T>
Extension that proxies to Observable.as + AutoDispose.autoDisposable
@CheckReturnValue()
inline fun <T : Any> Observable<T>.autoDispose(scope: Completable): ObservableSubscribeProxy<T>
Extension that proxies to Observable.as + AutoDispose.autoDisposable
@CheckReturnValue()
inline fun <T : Any> Single<T>.autoDispose(provider: ScopeProvider): SingleSubscribeProxy<T>
Extension that proxies to Single.as + AutoDispose.autoDisposable
@CheckReturnValue()
inline fun <T : Any> Single<T>.autoDispose(scope: Completable): SingleSubscribeProxy<T>
Extension that proxies to Single.as + AutoDispose.autoDisposable
@CheckReturnValue()
inline fun <T : Any> ParallelFlowable<T>.autoDispose(provider: ScopeProvider): ParallelFlowableSubscribeProxy<T>
Extension that proxies to ParallelFlowable.as + AutoDispose.autoDisposable
@CheckReturnValue()
inline fun <T : Any> ParallelFlowable<T>.autoDispose(scope: Completable): ParallelFlowableSubscribeProxy<T>
Extension that proxies to ParallelFlowable.as + AutoDispose.autoDisposable
withScope
Link copied to clipboard
inline fun withScope(scope: ScopeProvider, body: AutoDisposeContext.() -> Unit)
Executes a body with an AutoDisposeContext backed by the given scope.
inline fun withScope(completableScope: Completable, body: AutoDisposeContext.() -> Unit)
Executes a body with an AutoDisposeContext backed by the given completableScope.