SubscriptionReceiver
Extension receiver for referencing external instances needed when receiving subscription.
For receiver provider
internal val customClientKey = ContextPropertyKey<CustomClient>()
val ContextReceiver.customClient: CustomClient?
get() = get(customClientKey)
var ContextReceiverBuilder.customClient: CustomClient
get() = error("You cannot retrieve a builder property directly.")
set(value) = set(customClientKey, value)
inline fun <T> buildCustomSubscriptionKey(
id: SubscriptionId<T>,
crossinline subscribe: CustomClient.() -> Flow<T>
): SubscriptionKey<T> = buildSubscriptionKey(
id = id,
subscribe = {
val client = checkNotNull(customClient) { "customClient isn't available. Did you forget to set it up?" }
with(client) { subscribe() }
}
)
Content copied to clipboard
For receiver builder
SubscriptionReceiver {
customClient = newCustomClient()
}
Content copied to clipboard
For receiver executor
class ExampleSubscriptionKey(auto: Namespace) : SubscriptionKey<String> by buildCustomSubscriptionKey(
id = SubscriptionId(auto.value),
subscribe = { // CustomClient.() -> Flow<String>
doSomethingFlow()
}
)
Content copied to clipboard
Inheritors
Types
Link copied to clipboard
Default implementation for SubscriptionReceiver.