scala - How to end an infinite akka stream -
i'm new akka streams have case want use permutations infinite source. simplified example finite source this.
val future = source(1 100) .map { => if (i % 20 == 0) println(i); } .filter(_ == 42) .runwith(sink.fold[int, int](0)(keep.right))
this exemple outputs:
20 40 60 80 100
i'm fine source getting past 42
don't want exhaust entire stream before being able result.
val result: int = await.result(future, 1.second) result should be(42)
question is, how should end stream when i've found i'm looking for?
val future = source(1 100) .map { => if (i % 20 == 0) println(i); } .filter(_ == 42) .runwith(sink.head)
Comments
Post a Comment