本文整理汇总了Scala中monix.reactive.Observer类的典型用法代码示例。如果您正苦于以下问题:Scala Observer类的具体用法?Scala Observer怎么用?Scala Observer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Observer类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: TestObserver
//设置package包名称以及导入依赖的类
package walfie.gbf.raidfinder.util
import monix.execution.Ack
import monix.reactive.Observer
import scala.concurrent.Future
class TestObserver[T] extends Observer[T] {
var received = Vector.empty[T]
var errorsReceived = Vector.empty[Throwable]
var isComplete: Boolean = false
def onNext(elem: T): Future[Ack] = {
received = received :+ elem
Ack.Continue
}
def onError(e: Throwable): Unit = {
errorsReceived = errorsReceived :+ e
}
def onComplete(): Unit = {
isComplete = true
}
}
开发者ID:walfie,项目名称:gbf-raidfinder,代码行数:25,代码来源:TestObserver.scala
示例2: handle
//设置package包名称以及导入依赖的类
package de.m7w3.signal.events
import de.m7w3.signal.Logging
import monix.execution.Ack
import monix.execution.Ack.Continue
import monix.reactive.Observer
import scala.concurrent.Future
trait EventListener extends Observer[SignalDesktopEvent] {
def handle: PartialFunction[SignalDesktopEvent, Unit]
override def onNext(elem: SignalDesktopEvent): Future[Ack] = {
if (handle.isDefinedAt(elem)) {
handle.apply(elem)
}
Continue
}
}
abstract class SimpleEventListener extends EventListener with Logging {
override def onError(ex: Throwable): Unit = {
logger.error(s"Error in event listener ${getClass.getSimpleName}", ex)
}
override def onComplete(): Unit = {
logger.info(s"${getClass.getSimpleName} completed")
}
}
object EventListener {
def simple(onEvent: PartialFunction[SignalDesktopEvent, Unit]): EventListener = {
new SimpleEventListener() {
override def handle: PartialFunction[SignalDesktopEvent, Unit] = onEvent
}
}
}
开发者ID:ayoub-benali,项目名称:signal-desktop-client,代码行数:40,代码来源:EventListener.scala
注:本文中的monix.reactive.Observer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论