commonMain.ru.casperix.signals.concrete.Signal.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of signals Show documentation
Show all versions of signals Show documentation
Signals for all occasions
The newest version!
package ru.casperix.signals.concrete
import ru.casperix.signals.api.AbstractSignal
/**
* При срабатывании разово уведомляет всех подписчиков
*/
class Signal() : Promise, AbstractSignal<(Event) -> Unit, Slot>(SlotCollection()) {
override fun set(value: Event) {
forEach { listener ->
listener(value)
}
}
companion object {
fun pipe(vararg initiatorList: Future): Future {
val signal = Signal()
initiatorList.forEach { initiator ->
initiator.then { event ->
signal.set(event)
}
}
return signal
}
}
}