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

io.reactors.protocol.channel-protocols.scala Maven / Gradle / Ivy

The newest version!
package io.reactors
package protocol






/** Utilities that manipulate and transform channels.
 */
trait ChannelProtocols {
  implicit def channelOps[@spec(Int, Long, Double) T: Arrayable](ch: Channel[T]) =
    new ChannelProtocols.ChannelOps(ch)
}


object ChannelProtocols {
  class ChannelOps[@spec(Int, Long, Double) T: Arrayable](val ch: Channel[T]) {
    /** Returns a channel that executes a side-effect and forwards to the original.
     *
     *  @param f       side-effect to execute before forwarding an event
     *  @return        the new channel
     */
    def inject(f: T => Unit): Channel[T] = {
      val system = Reactor.self.system
      val c = system.channels.daemon.shortcut.open[T]
      c.events onEvent { x =>
        f(x)
        ch ! x
      }
      c.channel
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy