Interface Subscription

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Subscription
What a registration hands back: the one way to stop listening.

A distinct type and not a Runnable, because a Runnable handle returned from a Runnable-taking registrar can be handed straight back to it:


 Runnable handle = viewport.observeDispose(scene3d::dispose);
 viewport.observeDispose(handle);   // compiles; registers the unsubscriber as a listener
 

That program compiles, runs, and then unsubscribes something at a moment nobody chose, with no diagnostic anywhere. One method with a name of its own closes it for every registrar at once: the argument position takes a Runnable, a ChangeObserver or a Predicate, the return position takes a Subscription, and the two can never be confused.

It lives here rather than beside Widget because five registrars in four packages return it and two of those packages (limn.graphics, limn.i18n) do not depend on the widget layer at all. limn.concurrent is where the dependencies already point.

Cancelling twice is a no-op, which is a promise about the handle rather than about the removal: a handle drops the registration it captured on its first cancel() and does nothing thereafter, so it can never take a second listener off a list.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Stops the listening this handle was returned for.
  • Method Details

    • cancel

      void cancel()
      Stops the listening this handle was returned for. Idempotent. UI thread.