
io.reactors.protocol.communication-abstractions.scala Maven / Gradle / Ivy
The newest version!
package io.reactors
package protocol
trait CommunicationAbstractions {
trait Connection[T] {
def events: Events[T]
def subscription: Subscription
}
trait ServerSide[R, C] {
def channel: Channel[R]
def links: Events[C]
def subscription: Subscription
}
case class Valve[T](
channel: Channel[T],
available: Signal[Boolean],
subscription: Subscription
)
case class Pump[T](
buffer: EventBuffer[T],
subscription: Subscription
) {
def plug(valve: Valve[T])(implicit a: Arrayable[T]): Subscription = {
val pump = this
val forwardSub = pump.buffer.onEvent(x => valve.channel ! x)
def flush(): Unit = {
while (pump.buffer.nonEmpty && valve.available()) {
pump.buffer.dequeue()
}
}
val valveSub = valve.available.filter(_ == true) on {
flush()
}
val pumpSub = pump.buffer.available.filter(_ == true) on {
flush()
}
new Subscription.Composite(forwardSub, valveSub, pumpSub)
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy