onUnsubscribe

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

A callback to be executed when the subscriber cancels its subscription job (unsubscribes).

  • This callback is executed after the subscriber has been removed and after subscriberCount is decremented, i.e. the value represents the new number of subscribers.

  • There is no guarantee that this will be invoked exactly before a subscriber reappears. It may be so that a second subscriber 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 onUnsubscribe will wait for this one to complete.