ru.primetalk.synapse.rx.SimpleSignalProcessorRx.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of synapse-grid-rx_2.11 Show documentation
Show all versions of synapse-grid-rx_2.11 Show documentation
SynapseGrid is a framework for constructing reactive real-time immutable data flow systems. -core contains everything to run a single-threaded system, -akka contains everything to run systems over Akka actors, -slf4j - enables logging, -concurrent - running systems directly over ExecutorContext without the need for Akka, -examples - a few test systems. Also there are -frames - a framework for type construction with meta information (see relations.scala). -typed-expressions - a framework for defining parsers and generators for natural language. The current version is 1.4.0
///////////////////////////////////////////////////////////////
// © ООО «Праймтолк», 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 ru.primetalk.synapse.core.Signal
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
}