onSubscribe

open suspend fun PipelineContext<S, I, A>.onSubscribe(newSubscriberCount: Int)

A callback to be executed each time Store.subscribe is called.

  • This callback is executed after the subscriber count is incremented, i.e. the value represents the new number of subscribers.

  • There is no guarantee that the subscribers will not be able to subscribe when the store has not been started yet. But this function will be invoked as soon as the store is started, with the most recent subscriber count.

  • This function is invoked in the store's scope, not the subscriber's scope.

  • There is no guarantee that this will be invoked exactly before a subscriber reappears. It may be so that a second subscriber, for example, appears before the first one disappears (due to the parallel nature of coroutines). In that case, onSubscribe will be invoked first as if it was a second subscriber, and then onUnsubscribe will be invoked, as if there were more subscribers for a moment.

  • Suspending in this function will prevent other plugins from receiving the subscription event (i.e. next plugins that use onSubscribe will wait for this one to complete.