public class VirtualPublisher<T>
extends java.util.concurrent.atomic.AtomicReference<java.lang.Object>
implements org.reactivestreams.Publisher<T>
The implementation of Sink.asPublisher
needs to offer a Publisher
that
defers to the upstream that is connected during materialization. This would
be trivial if it were not for materialized value computations that may even
spawn the code that does pub.subscribe(sub)
in a Future, running concurrently
with the actual materialization. Therefore we implement a minimial shell here
that plugs the downstream and the upstream together as soon as both are known.
Using a VirtualProcessor would technically also work, but it would defeat the
purpose of subscription timeouts—the subscription would always already be
established from the Actor’s perspective, regardless of whether a downstream
will ever be connected.
One important consideration is that this Publisher
must not retain a reference
to the Subscriber
after having hooked it up with the real Publisher
, hence
the use of Inert.subscriber
as a tombstone.
Constructor and Description |
---|
VirtualPublisher() |
Modifier and Type | Method and Description |
---|---|
void |
registerPublisher(org.reactivestreams.Publisher<?> pub) |
void |
subscribe(org.reactivestreams.Subscriber<? super T> subscriber) |