设为首页 加入收藏

TOP

Akka(17): Stream:数据流基础组件-Source,Flow,Sink简介(五)
2017-10-09 13:43:40 】 浏览:7666
Tags:Akka Stream 数据流 基础 组件 -Source Flow Sink 简介
l mat=ActorMaterializer() implicit val ec=sys.dispatcher val s1: Source[Int,NotUsed] = Source(1 to 10) val sink: Sink[Any,Future[Done]] = Sink.foreach(println) val rg1: RunnableGraph[NotUsed] = s1.to(sink) val rg2: RunnableGraph[Future[Done]] = s1.toMat(sink)(Keep.right) val res1: NotUsed = rg1.run() Thread.sleep(1000) val res2: Future[Done] = rg2.run() res2.andThen { case _ => //sys.terminate() } val seq = Seq[Int](1,2,3) def toIterator() = seq.iterator val flow1: Flow[Int,Int,NotUsed] = Flow[Int].map(_ + 2) val flow2: Flow[Int,Int,NotUsed] = Flow[Int].map(_ * 3) val s2 = Source.fromIterator(toIterator) val s3 = s1 ++ s2 val s4: Source[Int,NotUsed] = s3.viaMat(flow1)(Keep.right) val s5: Source[Int,NotUsed] = s3.via(flow1).async.viaMat(flow2)(Keep.right) val s6: Source[Int,NotUsed] = s4.async.viaMat(flow2)(Keep.right) (s5.toMat(sink)(Keep.right).run()).andThen {case _ => } //sys.terminate()} s1.runForeach(println) val fres = s6.runFold(0)(_ + _) fres.onSuccess{case a => println(a)} fres.andThen{case _ => sys.terminate()} }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

首页 上一页 2 3 4 5 下一页 尾页 5/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇为什么要创建开放源码的PlayScala.. 下一篇Akka(23): Stream:自定义流构..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目