doWhileSubscribed
inline suspend fun SubscriptionAware.doWhileSubscribed(stopDelay: Duration = 1.seconds, minSubscribers: Int = 1, crossinline action: suspend () -> Unit)
Runs action while this has at least minSubscribers subscribers. This function will suspend forever.
Awaits until the SubscriptionAware.subscriberCount is at least minSubscribers and then invokes action.
The action is canceled when the subscriber count drops below minSubscribers for longer than stopDelay.
The action is restarted when the subscriber count reaches minSubscribers again.
The function will suspend until the SubscriptionAware is no longer needed (e.g. its scope is cancelled).
Parameters
stopDelay
the delay after which the action is cancelled if the subscriber count drops below minSubscribers.
minSubscribers
the minimum number of subscribers to keep the action running.
action
the action to invoke when the subscriber count is sufficient.