Module id.xfunction

Class SynchronousPublisher<T>

Object
SynchronousPublisher<T>
All Implemented Interfaces:
AutoCloseable, Flow.Publisher<T>
Direct Known Subclasses:
TransformProcessor

public class SynchronousPublisher<T> extends Object implements Flow.Publisher<T>, AutoCloseable
Publisher which has no internal queues and which delivers items to subscribers synchronously.

Items are delivered through Flow.Subscriber.onNext(Object):

  • using same thread where submit(Object) method is called
  • in same order in which subscribers were subscribed to this publisher

This publisher will never loose any item as it will block indefinitely until at least one subscriber requests and receives it.

  • Constructor Details

    • SynchronousPublisher

      public SynchronousPublisher()
  • Method Details

    • subscribe

      public void subscribe(Flow.Subscriber<? super T> subscriber)
      Specified by:
      subscribe in interface Flow.Publisher<T>
    • submit

      public void submit(T item)
      Publishes the given item to each current subscriber by synchronously invoking its onNext method.

      If there is no active subscribers, or none of the subscribers requested new items then this method blocks. It will unblock only when one of the following things happens:

    • closeExceptionally

      public void closeExceptionally(Throwable error)
      Unless already closed, issue onError to existing subscribers and disallows subsequent submit(Object) attempts. Future subscribers also receive the given error.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable