public class FlowAdapter extends Object
Flow.Publisher and AsyncIterator.| Modifier and Type | Method | Description |
|---|---|---|
static <T> AsyncIterator<T> |
toAsyncIterator(Flow.Publisher<? extends T> publisher) |
Convert a
Flow.Publisher into an AsyncIterator. |
static <T> Flow.Publisher<T> |
toPublisher(AsyncIterator<? extends T> asyncIterator) |
Convert an
AsyncIterator into a Flow.Publisher. |
static <T> Flow.Publisher<T> |
toPublisher(Supplier<AsyncIterator<? extends T>> asyncIteratorSupplier) |
public static <T> AsyncIterator<T> toAsyncIterator(Flow.Publisher<? extends T> publisher)
Flow.Publisher into an AsyncIterator. Calling a terminal method on a
pipeline including the returned iterator will start a subscription on publisher.
Elements will be requested as the returned iterator is consumed, and the returned iterator will
stop iteration when the publisher finishes or produces
an error.
Users of the returned AsyncIterator must call AsyncIterator.close() when they
have finished using the iterator so that publisher may clean up any associated
resources.
publisher - that will be subscribed to in order to yield elements from the returned
iteratorAsyncIterator that will iterate over elements produced via a
Flow.Subscription from the given publisherpublic static <T> Flow.Publisher<T> toPublisher(AsyncIterator<? extends T> asyncIterator)
AsyncIterator into a Flow.Publisher. Because AsyncIterators are
single consumer, the returned publisher should only be subscribed to once. When
asyncIterator is exhausted or returns an exception the iterator will be
closed and Flow.Subscriber will be notified accordingly. If
the Flow.Subscription is cancelled before iterator is complete, the iterator be closed as
well.
Exceptions produced by either iteration or by close will be delivered via
Flow.Subscriber.onError(Throwable). If both iteration and close produce exceptions, the
exception produced by close will be added as a suppressed exception to the iteration exception.
asyncIterator - used to produce elements published by the returned Flow.PublisherFlow.Publisher that supports a single subscription that will yield elements from
asyncIteratorpublic static <T> Flow.Publisher<T> toPublisher(Supplier<AsyncIterator<? extends T>> asyncIteratorSupplier)
Supplier of AsyncIterators into a
Flow.Publisher. Because AsyncIterators are single consumer, each subscription of the
returned publisher will generate a new AsyncIterator from asyncIteratorSupplier. When a
generated AsyncIterator is exhausted or returns an exception the iterator will be
closed and Flow.Subscriber will be notified accordingly. If
the Flow.Subscription is cancelled before iterator is complete, the iterator be closed as
well.
Exceptions produced by either iteration or by close will be delivered via
Flow.Subscriber.onError(Throwable). If both iteration and close produce exceptions, the
exception produced by close will be added as a suppressed exception to the iteration exception.
asyncIteratorSupplier - used to produce AsyncIterators of elements published by the
returned Flow.PublisherFlow.Publisher that supports multiple subscriptions that will yield elements from
AsyncIterators generated from asyncIteratorSupplierCopyright © 2018. All rights reserved.