wireTap and dropped elements

Hi all. Can def wireTap(f: Out => Unit) actually drop elements in practice? It uses Sink#foreach, which will always pull for an element IIUC.

I understand that the other variant (def wireTap(that: Graph[SinkShape[Out], _])) can and does drop elements by design, but I can’t see how the simpler thunk-based one could drop.

Thanks for your thoughts.

Hey Jason,

wireTap(Out => Unit) is implemented by wireTap(Sink.foreach(f)).named("wireTap") so the same holds true as for wireTap with a graph.

If you want to build a stream graph that would instead backpressure the main flow if the wiretapping branch cannot keep up you can do that from the flow API using .alsoTo(Sink.foreach(...))

1 Like

Thanks Johan. I’m still a little confused though – how can Sink#foreach propagate a backpressure signal? Doesn’t it always pull when receiving an element?

If the function passed to foreach takes time to process an element that leads to backpressure (if the entire stream graph is fused into one “island” it just means nothing else can execute, but if there are async boundaries that means “normal” backpressure).

Ah of course, that makes sense. Thanks!