Fixed 19039 for both scaladsl and javadsl

19039: Added cycle method to Source class for both scaladsl and javadsl. Test added.
This commit is contained in:
Oleksii Tkachuk 2016-03-22 21:59:52 -05:00
parent b3444fa1b0
commit 78e0a534f4
6 changed files with 61 additions and 0 deletions

View file

@ -90,6 +90,20 @@ object Source {
def fromIterator[O](f: function.Creator[java.util.Iterator[O]]): javadsl.Source[O, NotUsed] =
new Source(scaladsl.Source.fromIterator(() f.create().asScala))
/**
* Helper to create 'cycled' [[Source]] from iterator provider.
* Example usage:
*
* {{{
* Source.cycle(() -> Arrays.asList(1, 2, 3).iterator());
* }}}
*
* Start a new 'cycled' `Source` from the given elements. The producer stream of elements
* will continue infinitely by repeating the sequence of elements provided by function parameter.
*/
def cycle[O](f: function.Creator[java.util.Iterator[O]]): javadsl.Source[O, NotUsed] =
new Source(scaladsl.Source.cycle(() f.create().asScala))
/**
* Helper to create [[Source]] from `Iterable`.
* Example usage: