Interface AsyncStream<E>

  • Type Parameters:
    E - The type of the elements, usually a TransferableBlock

    public interface AsyncStream<E>
    An interface that represents an abstract asynchronous stream of elements that can be consumed. These streams are designed to be consumed by a single thread and do not support null elements.
    • Method Detail

      • getId

        Object getId()
        The id of the stream. Mostly used for logging. Implementations of this method must be thread safe.
      • poll

        @Nullable
        E poll()
        Reads the next element, if there is any to read. Otherwise it returns null. Calling this method before setting a callback with addOnNewDataListener(OnNewData) is illegal as it may imply losing information. Only the consumer thread can call this method.
        Returns:
        the next element to consume, which cannot be null, or null if there is no element ready yet.
      • addOnNewDataListener

        void addOnNewDataListener​(AsyncStream.OnNewData onNewData)
        Registers a callback. Once set, the callback cannot be changed. In order to call poll(), a callback has to be registered. Only the consumer thread can call this method.
        Parameters:
        onNewData -
      • cancel

        void cancel()
        Cancels this stream. Only the consumer thread can call this method.