Interface ChannelSupplier<T>
- All Superinterfaces:
io.activej.async.process.AsyncCloseable
- All Known Implementing Classes:
AbstractChannelSupplier,ChannelFileReader,Concat,Empty,OfAnotherReactor,OfAsyncSupplier,OfException,OfInputStream,OfIterator,OfLazyProvider,OfPromise,OfSupplier,OfValue,Remap
Promise of data that should be used serially
(each consecutive get()) operation should be called only after previous
get() operation finishes.
After supplier is closed, all subsequent calls to get() will return promise,
completed exceptionally.
If any exception is caught while supplying data items, AsyncCloseable.closeEx(Exception) method
should be called. All resources should be freed and the caught exception should be
propagated to all related processes.
If get() returns Promise of null, it represents end-of-stream
and means that no additional data should be queried.
-
Field Summary
Fields inherited from interface io.activej.async.process.AsyncCloseable
STATIC -
Method Summary
Modifier and TypeMethodDescriptiondefault ChannelSupplier<T>async()Creates and returns a newAbstractChannelSupplierbased on current ChannelSupplier and makes its promise complete asynchronously.default io.activej.promise.Promise<Void>bindTo(ChannelInput<T> to) Binds this ChannelSupplier to providedChannelInputstatic <T,A, R> io.activej.promise.Promise<R> collect(ChannelSupplier<T> supplier, A initialValue, io.activej.common.function.BiConsumerEx<A, T> accumulator, io.activej.common.function.FunctionEx<A, R> finisher) Collects data provided by thesupplierasynchronously and returns a promise of accumulated result.default ChannelSupplier<T>Creates and returns a newAbstractChannelSupplierbased on current ChannelSupplier and checks if its Promise's value(s) match(es) the predicate, leaving only those value(s) which pass the test.io.activej.promise.Promise<T>get()default ChannelSupplier<T>lenient()Creates and returns a newAbstractChannelSupplierbased on current ChannelSupplier.default <V> ChannelSupplier<V>Creates and returns a newAbstractChannelSupplierbased on current ChannelSupplier and when its Promise completes, applies providedfnto the result.default <V> ChannelSupplier<V>Creates and returns a newAbstractChannelSupplierbased on current ChannelSupplier and applies providedfnto its Promise asynchronously.default ChannelSupplier<T>Creates and returns a newAbstractChannelSupplierbased on current ChannelSupplier and when its Promise completes successfully, the result is accepted by the providedfn.static <T> io.activej.promise.Promise<Void>streamTo(io.activej.common.collection.Try<ChannelSupplier<T>> supplier, io.activej.common.collection.Try<ChannelConsumer<T>> consumer) default io.activej.promise.Promise<Void>streamTo(ChannelConsumer<T> consumer) Streams data from thisChannelSupplierto theChannelConsumeruntilget()returns a promise ofnull.default io.activej.promise.Promise<Void>streamTo(io.activej.promise.Promise<? extends ChannelConsumer<T>> consumer) static <T> io.activej.promise.Promise<Void>streamTo(io.activej.promise.Promise<ChannelSupplier<T>> supplier, io.activej.promise.Promise<ChannelConsumer<T>> consumer) default <A,R> io.activej.promise.Promise<R> toCollector(Collector<T, A, R> collector) toList()default <R> RTransforms this ChannelSupplier with the providedfn.default ChannelSupplier<T>Creates and returns a newAbstractChannelSupplierbased on current ChannelSupplier, when itsgetis called, its values will be returned until they don't fit thepredicate.default ChannelSupplier<T>withEndOfStream(UnaryOperator<io.activej.promise.Promise<Void>> fn) default ChannelSupplier<T>withExecutor(io.activej.async.process.AsyncExecutor executor) Creates and returns a newAbstractChannelSupplierbased on current ChannelSupplier and makes its promise executed by the providedexecutor.Methods inherited from interface io.activej.async.process.AsyncCloseable
close, closeEx
-
Method Details
-
get
io.activej.promise.Promise<T> get() -
transformWith
Transforms this ChannelSupplier with the providedfn.- Type Parameters:
R- returned result after transformation- Parameters:
fn-ChannelSupplierTransformerapplied to the ChannelSupplier
-
async
Creates and returns a newAbstractChannelSupplierbased on current ChannelSupplier and makes its promise complete asynchronously. -
withExecutor
Creates and returns a newAbstractChannelSupplierbased on current ChannelSupplier and makes its promise executed by the providedexecutor. -
peek
Creates and returns a newAbstractChannelSupplierbased on current ChannelSupplier and when its Promise completes successfully, the result is accepted by the providedfn. -
map
Creates and returns a newAbstractChannelSupplierbased on current ChannelSupplier and when its Promise completes, applies providedfnto the result. -
mapAsync
Creates and returns a newAbstractChannelSupplierbased on current ChannelSupplier and applies providedfnto its Promise asynchronously. -
filter
Creates and returns a newAbstractChannelSupplierbased on current ChannelSupplier and checks if its Promise's value(s) match(es) the predicate, leaving only those value(s) which pass the test. -
until
Creates and returns a newAbstractChannelSupplierbased on current ChannelSupplier, when itsgetis called, its values will be returned until they don't fit thepredicate. If one of the results passed thepredicate test, consequentgetoperations will returnnull. -
lenient
Creates and returns a newAbstractChannelSupplierbased on current ChannelSupplier. Even if its Promise completes with an exception,get()method will return a successfully completed Promise (in case of exception, withnullresult value). -
streamTo
Streams data from thisChannelSupplierto theChannelConsumeruntilget()returns a promise ofnull.If
get()returns a promise of exception or there was an exception whileChannelConsumeraccepted values, a promise ofexceptionwill be returned and the process will stop.- Parameters:
consumer- a consumer which accepts the provided by supplier data- Returns:
- a promise of
nullas a marker of completion of stream, or promise of exception, if there was an exception while streaming
-
streamTo
default io.activej.promise.Promise<Void> streamTo(io.activej.promise.Promise<? extends ChannelConsumer<T>> consumer) -
bindTo
Binds this ChannelSupplier to providedChannelInput -
toCollector
-
toList
- See Also:
-
withEndOfStream
-
collect
static <T,A, io.activej.promise.Promise<R> collectR> (ChannelSupplier<T> supplier, A initialValue, io.activej.common.function.BiConsumerEx<A, T> accumulator, io.activej.common.function.FunctionEx<A, R> finisher) Collects data provided by thesupplierasynchronously and returns a promise of accumulated result. This process will be getting values from thesupplier, until a promise ofnullis returned, which represents end of stream.If
getreturns a promise of exception or there was an exception whileaccumulatoraccepted values, a promise ofexceptionwill be returned and the process will stop.- Type Parameters:
T- a data type provided by thesupplierA- an intermediate accumulation data typeR- a data type of final result offinisher- Parameters:
supplier- aChannelSupplierwhich provides data to be collectedinitialValue- a value which will accumulate the results of accumulatoraccumulator- aBiConsumerwhich may perform some operations over provided by supplier data and accumulates the result to the initialValuefinisher- aFunctionwhich performs the final transformation of the accumulated value- Returns:
- a promise of accumulated result, transformed by the
finisher
-
streamTo
static <T> io.activej.promise.Promise<Void> streamTo(io.activej.promise.Promise<ChannelSupplier<T>> supplier, io.activej.promise.Promise<ChannelConsumer<T>> consumer) -
streamTo
static <T> io.activej.promise.Promise<Void> streamTo(io.activej.common.collection.Try<ChannelSupplier<T>> supplier, io.activej.common.collection.Try<ChannelConsumer<T>> consumer)
-