!str #16937 Remove section, in favor of via and separate flow

This commit is contained in:
Patrik Nordwall 2015-04-09 15:16:59 +02:00
parent bb0bed7d3c
commit b69988c190
36 changed files with 190 additions and 271 deletions

View file

@ -50,9 +50,11 @@ class FlowErrorDocSpec extends AkkaSpec {
case _: ArithmeticException => Supervision.Resume
case _ => Supervision.Stop
}
val source = Source(0 to 5).section(OperationAttributes.supervisionStrategy(decider)) {
_.filter(100 / _ < 50).map(elem => 100 / (5 - elem))
}
val flow = Flow[Int]
.filter(100 / _ < 50).map(elem => 100 / (5 - elem))
.withAttributes(OperationAttributes.supervisionStrategy(decider))
val source = Source(0 to 5).via(flow)
val result = source.runWith(Sink.fold(0)(_ + _))
// the elements causing division by zero will be dropped
// result here will be a Future completed with Success(150)
@ -68,13 +70,13 @@ class FlowErrorDocSpec extends AkkaSpec {
case _: IllegalArgumentException => Supervision.Restart
case _ => Supervision.Stop
}
val source = Source(List(1, 3, -1, 5, 7)).section(
OperationAttributes.supervisionStrategy(decider)) {
_.scan(0) { (acc, elem) =>
if (elem < 0) throw new IllegalArgumentException("negative not allowed")
else acc + elem
}
val flow = Flow[Int]
.scan(0) { (acc, elem) =>
if (elem < 0) throw new IllegalArgumentException("negative not allowed")
else acc + elem
}
.withAttributes(OperationAttributes.supervisionStrategy(decider))
val source = Source(List(1, 3, -1, 5, 7)).via(flow)
val result = source.grouped(1000).runWith(Sink.head)
// the negative element cause the scan stage to be restarted,
// i.e. start from 0 again

View file

@ -19,6 +19,7 @@ import scala.concurrent.ExecutionContext
import akka.stream.ActorFlowMaterializerSettings
import java.util.concurrent.atomic.AtomicInteger
import akka.stream.Supervision
import akka.stream.scaladsl.Flow
object IntegrationDocSpec {
import TwitterStreamQuickstartDocSpec._
@ -173,9 +174,9 @@ class IntegrationDocSpec extends AkkaSpec(IntegrationDocSpec.config) {
import Supervision.resumingDecider
val emailAddresses: Source[String, Unit] =
authors.section(supervisionStrategy(resumingDecider)) {
_.mapAsync(4, author => addressSystem.lookupEmail(author.handle))
}
authors.via(
Flow[Author].mapAsync(4, author => addressSystem.lookupEmail(author.handle))
.withAttributes(supervisionStrategy(resumingDecider)))
//#email-addresses-mapAsync-supervision
}
@ -263,15 +264,13 @@ class IntegrationDocSpec extends AkkaSpec(IntegrationDocSpec.config) {
.collect { case Some(phoneNo) => phoneNo }
//#blocking-map
val send = Flow[String]
.map { phoneNo =>
smsServer.send(TextMessage(to = phoneNo, body = "I like your tweet"))
}
.withAttributes(OperationAttributes.dispatcher("blocking-dispatcher"))
val sendTextMessages: RunnableFlow[Unit] =
phoneNumbers
.section(OperationAttributes.dispatcher("blocking-dispatcher")) {
_.map { phoneNo =>
smsServer.send(
TextMessage(to = phoneNo, body = "I like your tweet"))
}
}
.to(Sink.ignore)
phoneNumbers.via(send).to(Sink.ignore)
sendTextMessages.run()
//#blocking-map

View file

@ -28,13 +28,9 @@ class StreamBuffersRateSpec extends AkkaSpec {
//#materializer-buffer
//#section-buffer
val flow =
Flow[Int]
.section(OperationAttributes.inputBuffer(initial = 1, max = 1)) { sectionFlow =>
// the buffer size of this map is 1
sectionFlow.map(_ * 2)
}
.map(_ / 2) // the buffer size of this map is the default
val section = Flow[Int].map(_ * 2)
.withAttributes(OperationAttributes.inputBuffer(initial = 1, max = 1))
val flow = section.via(Flow[Int].map(_ / 2)) // the buffer size of this map is the default
//#section-buffer
}