@@ -5,7 +5,7 @@ import java.util
55import java .util .concurrent .Callable
66import java .util .function .{BiFunction , Consumer , Function , Supplier }
77import java .util .logging .Level
8- import java .util .{Comparator , List => JList }
8+ import java .util .{Comparator , stream , List => JList }
99
1010import org .reactivestreams .{Publisher , Subscriber , Subscription }
1111import reactor .core .Disposable
@@ -4591,16 +4591,37 @@ object Flux {
45914591
45924592 /**
45934593 * Create a [[Flux ]] that emits the items contained in the provided [[Stream ]].
4594- * A new iterator will be created for each subscriber.
4594+ * Keep in mind that a [[Stream ]] cannot be re-used, which can be problematic in
4595+ * case of multiple subscriptions or re-subscription (like with [[Flux.repeat() ]] or
4596+ * [[Flux.retry ]]). The [[Stream ]] is [[Stream.close closed ]] automatically
4597+ * by the operator on cancellation, error or completion.
45954598 * <p>
4596- * <img class="marble" src="https://raw.githubusercontent.com/reactor/reactor-core/v3.0.5 .RELEASE/src/docs/marble/fromstream.png" alt="">
4599+ * <img class="marble" src="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.1 .RELEASE/src/docs/marble/fromstream.png" alt="">
45974600 * <p>
45984601 *
45994602 * @param s the [[Stream ]] to read data from
4600- * @tparam T the [[Stream ]] type to flux
4603+ * @tparam T The type of values in the source [[Stream ]] and resulting Flux
46014604 * @return a new [[Flux ]]
46024605 */
4603- def fromStream [T ](s : Stream [T ]): Flux [T ] = Flux .fromIterable(s)
4606+ def fromStream [T ](s : Stream [T ]) = Flux (JFlux .fromStream(s))
4607+
4608+ /**
4609+ * Create a [[Flux ]] that emits the items contained in a [[Stream ]] created by
4610+ * the provided [[Function0 ]] for each subscription. The [[Stream ]] is
4611+ * [[Stream.close closed ]] automatically by the operator on cancellation, error
4612+ * or completion.
4613+ * <p>
4614+ * <img class="marble" src="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.1.RELEASE/src/docs/marble/fromstream.png" alt="">
4615+ * <p>
4616+ *
4617+ * @param streamSupplier the [[Function0 ]] that generates the [[Stream ]] from
4618+ * which to read data
4619+ * @tparam T The type of values in the source [[Stream ]] and resulting Flux
4620+ * @return a new [[Flux ]]
4621+ */
4622+ def fromStream [T ](streamSupplier : () => Stream [T ]) = Flux (JFlux .fromStream[T ](new Supplier [stream.Stream [_ <: T ]] {
4623+ override def get () = streamSupplier()
4624+ }))
46044625
46054626 /**
46064627 * Generate signals one-by-one via a consumer callback.
0 commit comments