Class InternalFlowUtils
java.lang.Object
dev.langchain4j.internal.InternalFlowUtils
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Flow.Publisher<T> failedPublisher(Throwable error) AFlow.Publisherthat fails every subscriber with the given error: it callsonSubscribewithEMPTY_SUBSCRIPTION, thenonError.static <T> Flow.Publisher<T> failPublisherOnThrow(Object target, String method, Supplier<Flow.Publisher<T>> operation) LikefailPublisherOnThrow(Supplier), but anullpublisher fails with anIllegalStateExceptionthat names the method that returned it: the class name oftarget, thenmethod, for example"<class name of target>.doChat(ChatRequest) returned null".static <T> Flow.Publisher<T> failPublisherOnThrow(Supplier<Flow.Publisher<T>> operation) Calls an operation that returns aFlow.Publisherso that the caller never sees it throw, which is the rule for every method that returns aPublisher: anything the operation throws, including anError, is returned as afailed publisher, and anullpublisher as a publisher failed with anIllegalStateException.
-
Field Details
-
EMPTY_SUBSCRIPTION
-
-
Constructor Details
-
InternalFlowUtils
public InternalFlowUtils()
-
-
Method Details
-
failedPublisher
AFlow.Publisherthat fails every subscriber with the given error: it callsonSubscribewithEMPTY_SUBSCRIPTION, thenonError. -
failPublisherOnThrow
Calls an operation that returns aFlow.Publisherso that the caller never sees it throw, which is the rule for every method that returns aPublisher: anything the operation throws, including anError, is returned as afailed publisher, and anullpublisher as a publisher failed with anIllegalStateException. This is thePublishercounterpart ofCompletableFutureUtils.failOnThrow(Supplier).Use
failPublisherOnThrow(Object, String, Supplier)when the operation can returnnull, so that the message names the method that did.- Parameters:
operation- the operation that returns the publisher- Returns:
- the publisher returned by the operation, or a failed publisher
-
failPublisherOnThrow
public static <T> Flow.Publisher<T> failPublisherOnThrow(Object target, String method, Supplier<Flow.Publisher<T>> operation) LikefailPublisherOnThrow(Supplier), but anullpublisher fails with anIllegalStateExceptionthat names the method that returned it: the class name oftarget, thenmethod, for example"<class name of target>.doChat(ChatRequest) returned null".- Parameters:
target- the object whose method the operation callsmethod- the method the operation calls, for example"doChat(ChatRequest)"operation- the operation that returns the publisher- Returns:
- the publisher returned by the operation, or a failed publisher
-