All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.hnau.jutils.producer.ObservingProducer.kt Maven / Gradle / Ivy

There is a newer version: 2.1.1
Show newest version
package ru.hnau.jutils.producer

import ru.hnau.jutils.producer.detacher.ProducerDetachers


class ObservingProducer(
        private val producersProducer: Producer>
) : StateProducer() {

    private val detachers = ProducerDetachers()

    private var producerInner: Producer? = null
        set(value) = synchronized(this) {
            field?.detach(this::update)
            field = value
            value?.attach(this::update)
        }

    override fun onFirstAttached() {
        super.onFirstAttached()
        producersProducer.attach(detachers) { producerInner = it }
    }

    override fun onLastDetached() {
        detachers.detachAllAndClear()
        super.onLastDetached()
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy