Class SubscriptionHandle

  • All Implemented Interfaces:

    
    public final class SubscriptionHandle<T extends Object>
    
                        

    One subscription, and the rendezvous that tells you it exists.

    messages is cold and can be collected only once - a handle is a single subscription, not a factory for them, and a second collection throws IllegalStateException. Call NatsScope.subscribe again for a second subscriber; that is also how fan-out is expressed, a handle per collector.

    val orders = subscribe<OrderEvent>("orders")
    launch { orders.messages.collect { ... } }
    orders.started()
    publish("orders", OrderEvent("no race"))
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private final Flow<T> messages
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Flow<T> getMessages()
      final Unit started(Duration timeout) Suspends until this subscription is live on the server: until messages has been collected, registering the SUB, and until the server has acknowledged it.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • started

         final Unit started(Duration timeout)

        Suspends until this subscription is live on the server: until messages has been collected, registering the SUB, and until the server has acknowledged it. Anything published after this returns reaches this subscriber - from any connection, not only this klient's.

        Parameters:
        timeout - How long to wait for the server to acknowledge the subscription.