class Publisher {
public Subscription subscribe(Consumer<NewsLetter> subscriber) {
register(subscriber);
// return a Subscription which unregisters the original subscriber
return () -> unregister(subscriber);
}
}
Subscriptions can also be combined using combine and and,
which allows for multiple subscriptions to be unsubscribed together. This is
useful when they share the same lifecycle, for example, when performing
cleanup for the same object.
| Modifier and Type | Field and Description |
|---|---|
| public static final Subscription | EMPTY
An empty subscription. |
| Modifier and Type | Method and Description |
|---|---|
| public default Subscription | Returns: a combinedSubscription which will cancel both when
cancelled, never nullanother other)Subscription, cannot be nullCombines this |
| public static Subscription | Returns: aSubscription, never nullan array of subscriptions to combine, cannot be subscriptions)null or contain nullReturns a |
| public void |
| EMPTY | back to summary |
|---|---|
| public static final Subscription EMPTY An empty subscription. Does nothing when cancelled. | |
| and | back to summary |
|---|---|
| public default Subscription and(Subscription other) Combines this This is equivalent to
| |
| combine | back to summary |
|---|---|
| public static Subscription combine(Subscription... subscriptions) Returns a
| |
| unsubscribe | back to summary |
|---|---|
| public void unsubscribe() Cancels this subscription, or does nothing if already cancelled. Implementation Specification Implementors must ensure the implementation is idempotent (a no-op if called more than once). | |