Void/Unit subscripable
This commit is contained in:
parent
9ad1c8e82a
commit
d18399795b
@ -66,6 +66,44 @@ interface ISubscriptable<V> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface IUnitSubscripable : ISubscriptable<Unit> {
|
||||||
|
fun addListener(listener: Runnable): ISubscriptable.L
|
||||||
|
|
||||||
|
override fun addListener(listener: Consumer<Unit>): ISubscriptable.L {
|
||||||
|
return addListener(Runnable { listener.accept(Unit) })
|
||||||
|
}
|
||||||
|
|
||||||
|
class Impl : IUnitSubscripable, Runnable {
|
||||||
|
private inner class L(val callback: Runnable) : ISubscriptable.L {
|
||||||
|
private var isRemoved = false
|
||||||
|
|
||||||
|
init {
|
||||||
|
subscribers.add(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun remove() {
|
||||||
|
if (!isRemoved) {
|
||||||
|
isRemoved = true
|
||||||
|
queue.add(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val subscribers = ReferenceLinkedOpenHashSet<L>(0)
|
||||||
|
private val queue = ReferenceArraySet<L>(0)
|
||||||
|
|
||||||
|
override fun addListener(listener: Runnable): ISubscriptable.L {
|
||||||
|
return L(listener)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun run() {
|
||||||
|
queue.forEach { subscribers.remove(it) }
|
||||||
|
queue.clear()
|
||||||
|
subscribers.forEach { it.callback.run() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
interface IFloatSubcripable : ISubscriptable<Float> {
|
interface IFloatSubcripable : ISubscriptable<Float> {
|
||||||
@Deprecated("Use type specific listener")
|
@Deprecated("Use type specific listener")
|
||||||
override fun addListener(listener: Consumer<Float>): ISubscriptable.L {
|
override fun addListener(listener: Consumer<Float>): ISubscriptable.L {
|
||||||
|
Loading…
Reference in New Issue
Block a user