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

ru.primetalk.synapse.rx.SimpleSignalProcessorRx.scala Maven / Gradle / Ivy

///////////////////////////////////////////////////////////////
// © ООО «Праймтолк», 2011-2013                              //
// Все права принадлежат компании ООО «Праймтолк».           //
///////////////////////////////////////////////////////////////
/**
 * SynapseGrid
 * © Primetalk Ltd., 2013.
 * All rights reserved.
 * Authors: A.Zhizhelev, A.Nehaev
 *
 * Created: 06.12.13, zhizhelev
 */
package ru.primetalk.synapse.rx

import ru.primetalk.synapse.core._
import rx.lang.scala.{Observable, Observer, Subject}
import scala.util.Try

class SimpleSignalProcessorRx(sp: SimpleSignalProcessor) {
  private
  val rxInputSubject = Subject[Signal[_]]()
  private
  val rxOutputSubject = Subject[Signal[_]]()
  rxInputSubject.subscribe { s =>
    val res = Try(sp(s))
    res.foreach(_.foreach(rxOutputSubject.onNext))
    res.recover { case (e: Throwable) => rxOutputSubject.onError(e)}
  }

  val rxInput: Observer[Signal[_]] = rxInputSubject
  val rxOutput: Observable[Signal[_]] = rxOutputSubject
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy