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() }
}
)

For receiver builder

SubscriptionReceiver {
customClient = newCustomClient()
}

For receiver executor

class ExampleSubscriptionKey(auto: Namespace) : SubscriptionKey<String> by buildCustomSubscriptionKey(
id = SubscriptionId(auto.value),
subscribe = { // CustomClient.() -> Flow<String>
doSomethingFlow()
}
)

Inheritors

Types

Link copied to clipboard

Default implementation for SubscriptionReceiver.

Functions

Link copied to clipboard
abstract operator fun <T : Any> get(key: ContextPropertyKey<T>): T?