Top Description Fields Methods
javafx.util

public Interface Subscription

Annotations
@FunctionalInterface
Imports
java.util.List, .Objects

Represents a cancel or cleanup operation for an action that can be cancelled or that allocated resources. Subscriptions can be obtained, for example, as a result of registering a callback, starting a timer, or allocating resources. They provide a convenient way for subscribers to cancel these actions at a later time, without requiring additional information or even access to the source from where they were originally obtained.
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.

Since
21

Field Summary

Modifier and TypeField and Description
public static final Subscription
EMPTY

An empty subscription.

Method Summary

Modifier and TypeMethod and Description
public default Subscription

Returns:

a combined Subscription which will cancel both when cancelled, never null
and
(Subscription
another Subscription, cannot be null
other
)

Combines this Subscription with the given Subscription and returns a new Subscription which will cancel both when cancelled.

public static Subscription

Returns:

a Subscription, never null
combine
(Subscription...
an array of subscriptions to combine, cannot be null or contain null
subscriptions
)

Returns a Subscription which combines all of the given subscriptions.

public void
unsubscribe()

Cancels this subscription, or does nothing if already cancelled.

Field Detail

EMPTYback to summary
public static final Subscription EMPTY

An empty subscription. Does nothing when cancelled.

Method Detail

andback to summary
public default Subscription and(Subscription other)

Combines this Subscription with the given Subscription and returns a new Subscription which will cancel both when cancelled.

This is equivalent to Subscription.combine(this, other).

Parameters
other:Subscription

another Subscription, cannot be null

Returns:Subscription

a combined Subscription which will cancel both when cancelled, never null

Exceptions
NullPointerException:
when other is null
combineback to summary
public static Subscription combine(Subscription... subscriptions)

Returns a Subscription which combines all of the given subscriptions.

Parameters
subscriptions:Subscription[]

an array of subscriptions to combine, cannot be null or contain null

Returns:Subscription

a Subscription, never null

Exceptions
NullPointerException:
when subscriptions is null or contains null
unsubscribeback 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).