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

public interface ChannelSupplier<T> extends io.activej.async.process.AsyncCloseable
This interface represents supplier of 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.

  • Method Details

    • get

      io.activej.promise.Promise<T> get()
    • transformWith

      default <R> R transformWith(ChannelSupplierTransformer<T,R> fn)
      Transforms this ChannelSupplier with the provided fn.
      Type Parameters:
      R - returned result after transformation
      Parameters:
      fn - ChannelSupplierTransformer applied to the ChannelSupplier
    • async

      default ChannelSupplier<T> async()
      Creates and returns a new AbstractChannelSupplier based on current ChannelSupplier and makes its promise complete asynchronously.
    • withExecutor

      default ChannelSupplier<T> withExecutor(io.activej.async.process.AsyncExecutor executor)
      Creates and returns a new AbstractChannelSupplier based on current ChannelSupplier and makes its promise executed by the provided executor.
    • peek

      default ChannelSupplier<T> peek(Consumer<? super T> fn)
      Creates and returns a new AbstractChannelSupplier based on current ChannelSupplier and when its Promise completes successfully, the result is accepted by the provided fn.
    • map

      default <V> ChannelSupplier<V> map(io.activej.common.function.FunctionEx<? super T,? extends V> fn)
      Creates and returns a new AbstractChannelSupplier based on current ChannelSupplier and when its Promise completes, applies provided fn to the result.
    • mapAsync

      default <V> ChannelSupplier<V> mapAsync(Function<? super T,io.activej.promise.Promise<V>> fn)
      Creates and returns a new AbstractChannelSupplier based on current ChannelSupplier and applies provided fn to its Promise asynchronously.
    • filter

      default ChannelSupplier<T> filter(Predicate<? super T> predicate)
      Creates and returns a new AbstractChannelSupplier based 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

      default ChannelSupplier<T> until(Predicate<? super T> predicate)
      Creates and returns a new AbstractChannelSupplier based on current ChannelSupplier, when its get is called, its values will be returned until they don't fit the predicate. If one of the results passed the predicate test, consequent get operations will return null.
    • lenient

      default ChannelSupplier<T> lenient()
      Creates and returns a new AbstractChannelSupplier based on current ChannelSupplier. Even if its Promise completes with an exception, get() method will return a successfully completed Promise (in case of exception, with null result value).
    • streamTo

      default io.activej.promise.Promise<Void> streamTo(ChannelConsumer<T> consumer)
      Streams data from this ChannelSupplier to the ChannelConsumer until get() returns a promise of null.

      If get() returns a promise of exception or there was an exception while ChannelConsumer accepted values, a promise of exception will be returned and the process will stop.

      Parameters:
      consumer - a consumer which accepts the provided by supplier data
      Returns:
      a promise of null as 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

      default io.activej.promise.Promise<Void> bindTo(ChannelInput<T> to)
      Binds this ChannelSupplier to provided ChannelInput
    • toCollector

      default <A, R> io.activej.promise.Promise<R> toCollector(Collector<T,A,R> collector)
      See Also:
    • toList

      default io.activej.promise.Promise<List<T>> toList()
      See Also:
    • withEndOfStream

      default ChannelSupplier<T> withEndOfStream(UnaryOperator<io.activej.promise.Promise<Void>> fn)
    • collect

      static <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 the supplier asynchronously and returns a promise of accumulated result. This process will be getting values from the supplier, until a promise of null is returned, which represents end of stream.

      If get returns a promise of exception or there was an exception while accumulator accepted values, a promise of exception will be returned and the process will stop.

      Type Parameters:
      T - a data type provided by the supplier
      A - an intermediate accumulation data type
      R - a data type of final result of finisher
      Parameters:
      supplier - a ChannelSupplier which provides data to be collected
      initialValue - a value which will accumulate the results of accumulator
      accumulator - a BiConsumer which may perform some operations over provided by supplier data and accumulates the result to the initialValue
      finisher - a Function which 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)