Package rx.subscriptions
Class Subscriptions
- java.lang.Object
-
- rx.subscriptions.Subscriptions
-
public final class Subscriptions extends java.lang.Object
Helper methods and utilities for creating and working withSubscription
objects
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
Subscriptions.FutureSubscription
Naming classes helps with debugging.(package private) static class
Subscriptions.Unsubscribed
Naming classes helps with debugging.
-
Field Summary
Fields Modifier and Type Field Description private static Subscriptions.Unsubscribed
UNSUBSCRIBED
ASubscription
that does nothing when its unsubscribe method is called.
-
Constructor Summary
Constructors Modifier Constructor Description private
Subscriptions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Subscription
create(Action0 unsubscribe)
Creates and returns aSubscription
that invokes the givenAction0
when unsubscribed.static Subscription
empty()
static Subscription
from(java.util.concurrent.Future<?> f)
Converts aFuture
into aSubscription
and cancels it when unsubscribed.static CompositeSubscription
from(Subscription... subscriptions)
Converts a set ofSubscription
s into aCompositeSubscription
that groups the multiple Subscriptions together and unsubscribes from all of them together.static Subscription
unsubscribed()
Returns aSubscription
to whichunsubscribe
does nothing, as it is already unsubscribed.
-
-
-
Field Detail
-
UNSUBSCRIBED
private static final Subscriptions.Unsubscribed UNSUBSCRIBED
ASubscription
that does nothing when its unsubscribe method is called.
-
-
Method Detail
-
empty
public static Subscription empty()
Returns aSubscription
to whichunsubscribe
does nothing except to changeisUnsubscribed
totrue
. It's stateful andisUnsubscribed
indicates ifunsubscribe
is called, which is different fromunsubscribed()
.Subscription empty = Subscriptions.empty(); System.out.println(empty.isUnsubscribed()); // false empty.unsubscribe(); System.out.println(empty.isUnsubscribed()); // true
- Returns:
- a
Subscription
to whichunsubscribe
does nothing except to changeisUnsubscribed
totrue
-
unsubscribed
public static Subscription unsubscribed()
Returns aSubscription
to whichunsubscribe
does nothing, as it is already unsubscribed. ItsisUnsubscribed
always returnstrue
, which is different fromempty()
.Subscription unsubscribed = Subscriptions.unsubscribed(); System.out.println(unsubscribed.isUnsubscribed()); // true
- Returns:
- a
Subscription
to whichunsubscribe
does nothing, as it is already unsubscribed - Since:
- 1.1.0
-
create
public static Subscription create(Action0 unsubscribe)
Creates and returns aSubscription
that invokes the givenAction0
when unsubscribed.- Parameters:
unsubscribe
- Action to invoke on unsubscribe.- Returns:
Subscription
-
from
public static Subscription from(java.util.concurrent.Future<?> f)
Converts aFuture
into aSubscription
and cancels it when unsubscribed.- Parameters:
f
- theFuture
to convert- Returns:
- a
Subscription
that wrapsf
-
from
public static CompositeSubscription from(Subscription... subscriptions)
Converts a set ofSubscription
s into aCompositeSubscription
that groups the multiple Subscriptions together and unsubscribes from all of them together.- Parameters:
subscriptions
- the Subscriptions to group together- Returns:
- a
CompositeSubscription
representing thesubscriptions
set
-
-