Skip to content

ConflatedBroadcastChannel as ReadWriteProperty #245

Closed
@jcornaz

Description

@jcornaz

Hello,

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 implement ReadWriteProperty?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions