Class PythonPublishers
java.lang.Object
io.micronaut.context.python.PythonPublishers
Publisher adapters of the Python bridge that keep the reactive context of the subscriber. The
Reactor context (a reactive transaction status, the propagated context of an HTTP request) flows
from the subscriber up to the source through Reactor subscribers only, so every adapter here is a
Reactor operator when Reactor is on the class path; without Reactor no such context exists and the
plain Reactive Streams adapters are used.
- Since:
- 5.2.0
-
Method Summary
Modifier and TypeMethodDescriptiondeferred(Function<PythonReactiveContext, CompletableFuture<Object>> starter) A publisher that starts a deferred computation (a Python coroutine) when it is first subscribed, in the reactive context of that subscriber, and shares the result with every subscriber: a cancelled subscription does not cancel the shared future, so a later subscriber (atimeout().retry()) still receives the result.static <T,R> Publisher <R> Map the items of a publisher Python code returned.static voidsubscribe(Publisher<?> publisher, Subscriber<Object> subscriber, @Nullable PythonReactiveContext reactiveContext) Subscribe to a publisher within a reactive context: the propagated context is in scope during the subscription and the Reactor context is written above the subscriber, so the source sees both.
-
Method Details
-
map
Map the items of a publisher Python code returned.Publishers.map(Publisher, Function)wraps the subscriber in a plain Reactive Streams subscriber, so a source such asMono.deferContextualor aMANDATORYtransaction would see an empty Reactor context; here aMonostays aMonoand the context of the subscriber is kept.- Type Parameters:
T- The source item typeR- The mapped item type- Parameters:
publisher- The source publishermapper- The item mapper- Returns:
- The mapped publisher
-
deferred
public static Publisher<Object> deferred(Function<PythonReactiveContext, CompletableFuture<Object>> starter) A publisher that starts a deferred computation (a Python coroutine) when it is first subscribed, in the reactive context of that subscriber, and shares the result with every subscriber: a cancelled subscription does not cancel the shared future, so a later subscriber (atimeout().retry()) still receives the result.- Parameters:
starter- Starts the computation in the given context- Returns:
- The publisher
-
subscribe
public static void subscribe(Publisher<?> publisher, Subscriber<Object> subscriber, @Nullable PythonReactiveContext reactiveContext) Subscribe to a publisher within a reactive context: the propagated context is in scope during the subscription and the Reactor context is written above the subscriber, so the source sees both.- Parameters:
publisher- The publishersubscriber- The subscriberreactiveContext- The reactive context, ornullfor a plain subscription
-