Class CachedObservable<T>

  • Type Parameters:
    T - the source element type

    public final class CachedObservable<T>
    extends Observable<T>
    An observable which auto-connects to another observable, caches the elements from that observable but allows terminating the connection and completing the cache.
    • Constructor Detail

      • CachedObservable

        private CachedObservable​(Observable.OnSubscribe<T> onSubscribe,
                                 CachedObservable.CacheState<T> state)
        Private constructor because state needs to be shared between the Observable body and the onSubscribe function.
        Parameters:
        onSubscribe -
        state -
    • Method Detail

      • from

        public static <T> CachedObservable<T> from​(Observable<? extends T> source)
        Creates a cached Observable with a default capacity hint of 16.
        Type Parameters:
        T - the value type
        Parameters:
        source - the source Observable to cache
        Returns:
        the CachedObservable instance
      • from

        public static <T> CachedObservable<T> from​(Observable<? extends T> source,
                                                   int capacityHint)
        Creates a cached Observable with the given capacity hint.
        Type Parameters:
        T - the value type
        Parameters:
        source - the source Observable to cache
        capacityHint - the hint for the internal buffer size
        Returns:
        the CachedObservable instance
      • isConnected

        boolean isConnected()
        Check if this cached observable is connected to its source.
        Returns:
        true if already connected
      • hasObservers

        boolean hasObservers()
        Returns true if there are observers subscribed to this observable.
        Returns: