Hi Tim, In the example code you backpressure on overflow, detecting back pressure is tricky as it is about detecting lack of demand flowing upstream, which could be caused by other reasons than the buffer overflowing.
I think that if you really need to know if the buffer is full it the best way would be to create a custom buffering GraphStage that signals that. In general you should prefer the GraphStage API to using the ActorSubscriber and ActorPublisher abstractions unless you explicitly need an actor for some reason - they will force an async boundary on you and is easier to get wrong than the GraphStage API which explicitly deals with demand. -- Johan Andrén Akka Team, Lightbend Inc. On Saturday, April 30, 2016 at 12:51:33 AM UTC+2, Tim Harper wrote: > > A pretty common thing I've to do is to call a (non-blocking, brief) > callback in the event of an overflow. Usually to send a quick message to > the logger. > > Here's how I normally solve the problem: > > val (input, completed) = Source.actorRef[Int](0, > OverflowStrategy.dropNew). > conflate { (prior, overflown) => > println(s"dropping overflown ${overflown}") > prior > }. > buffer(10, OverflowStrategy.backpressure). > async. > toMat(Sink.foreach { n => > println(n) > Thread.sleep(100) > })(Keep.both). > run > > (1 to 50).foreach { n => > input ! n > println(s"sent ${n}") > Thread.sleep(10) > } > > > (full source here > <https://gist.github.com/timcharper/74e1182badd8458d723bca4c8641280f>) > > But this is rather verbose. Is there a more concise way to have support > behavior? > > Another problem with this approach is that I'm creating two async > boundaries being created (after the actorRef, and then after the conflate); > that's less efficient than I'd prefer. > > Is the best way to do this is to create a custom ActorSubscriber ? > > Tim > -- >>>>>>>>>> Read the docs: http://akka.io/docs/ >>>>>>>>>> Check the FAQ: >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at https://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.