ConflatedBroadcastChannel as ReadWriteProperty
See original GitHub issueHello,
In our code base, we found useful to define the folowing extension functions:
operator fun <T> ConflatedBroadcastChannel<T>.getValue(thisRef: Any, property: KProperty<*>): T = value
operator fun <T> ConflatedBroadcastChannel<T>.setValue(thisRef: Any, property: KProperty<*>, value: T) {
offer(value)
}
They allow us to use the following pattern:
class MyClass {
private val _value = ConflatedBroadcastChannel(0)
var value by _value
fun openValueSubscription() = _value.openSubscription()
}
May I ask what do you think about this ? Do you think it is an anti-pattern ?
- If yes, why? And how would you achieve better generic observer pattern with coroutines?
- If no, what would you think about making
ConflatedBroadcastChannel
implementReadWriteProperty
?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:20 (20 by maintainers)
Top Results From Across the Web
Kotlin delegated property for Datastore Preferences library
OnSharedPreferenceChangeListener, emit changes into ConflatedBroadcastChannel and then convert it into Flow. Firstly, this approach produces a ...
Read more >ReadWriteProperty - Kotlin Programming Language
Implements the core logic of a property delegate for a read/write property that calls callback functions when changed. abstract class ObservableProperty<V> :
Read more >Kotlin delegated property for Datastore Preferences library
Secondly, ConflatedBroadcastChannel deprecated and should be replaced with StateFlow. In this case, DataStore comes out as the winner.
Read more >Kotlin ConflatedBroadcastChannel.offer() doesn't work?
Make sure you properly work with receiving values. If you use the ConflatedBroadcastChannel, you can use either OpenSubscription to get a ...
Read more >Automated Malware Analysis Report for LBKj5ozFfN.apk
ConflatedBroadcastChannel.kotlin_metadata, data, 1955 ... ReadWriteProperty.kotlin_metadata, data, 293. MutexImpl.kotlin_metadata, data, 2181.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I consider better extending the interface (your alternative).
Thanks @fvasco, I like the interfaces you propose.
I would only propose these changes:
SubscribableChannel
bySubscribable
andConflatedSubscribableChannel
byConflatedSubscribable
because they are not necessarilyChannel
. They only provide a way to open new channels.out
variance forSubscribableChannel
andConflatedSubscribableChannel
And I would either:
Make
ConflatedSubscribable
implementReadOnlyPropery
andConflatedBroadcastChannel
implementReadWriteProperty
Or provide: