Docs: Source.repeat (and friends) (#28615)

This commit is contained in:
Enno 2020-02-19 09:03:59 +01:00 committed by GitHub
parent d946abd8d7
commit cff15cf40d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 64 additions and 16 deletions

View file

@ -1,20 +1,34 @@
# Source.repeat
Stream a single object repeatedly
Stream a single object repeatedly.
@ref[Source operators](../index.md#source-operators)
@@@div { .group-scala }
## Signature
@@signature [Source.scala](/akka-stream/src/main/scala/akka/stream/scaladsl/Source.scala) { #repeat }
@@@
@apidoc[Source.repeat](Source$) { scala="#repeat[T](element:T):akka.stream.scaladsl.Source[T,akka.NotUsed]" java="#repeat(T)" }
## Description
Stream a single object repeatedly
This source emits a single element repeatedly. It never completes, if you want the stream to be finite you will need to limit it by combining with another operator
See also:
* @ref:[`single`](single.md) Stream a single object once.
* @ref:[`tick`](tick.md) A periodical repetition of an arbitrary object.
* @ref:[`cycle`](cycle.md) Stream iterator in cycled manner.
## Example
This example prints the first 4 elements emitted by `Source.repeat`.
Scala
: @@snip [snip](/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SourceSpec.scala) { #repeat }
Java
: @@snip [snip](/akka-stream-tests/src/test/java/akka/stream/javadsl/SourceTest.java) { #repeat }
## Reactive Streams semantics

View file

@ -1,20 +1,22 @@
# Source.single
Stream a single object
Stream a single object once.
@ref[Source operators](../index.md#source-operators)
@@@div { .group-scala }
## Signature
@@signature [Source.scala](/akka-stream/src/main/scala/akka/stream/scaladsl/Source.scala) { #single }
@@@
@apidoc[Source.single](Source$) { scala="#single[T](element:T):akka.stream.scaladsl.Source[T,akka.NotUsed]" java="#single(T)" }
## Description
Stream a single object
Stream a single object once and complete after thereafter.
See also:
* @ref:[`repeat`](repeat.md) Stream a single object repeatedly.
* @ref:[`tick`](tick.md) A periodical repetition of an arbitrary object.
* @ref:[`cycle`](cycle.md) Stream iterator in cycled manner.
## Examples

View file

@ -28,6 +28,11 @@ example for achieving a periodical element that changes over time.
@@@
See also:
* @ref:[`repeat`](repeat.md) Stream a single object repeatedly.
* @ref:[`cycle`](cycle.md) Stream iterator in cycled manner.
## Examples
This first example prints to standard out periodically:

View file

@ -37,8 +37,8 @@ These built-in sources are available from @scala[`akka.stream.scaladsl.Source`]
|Source|<a name="maybe"></a>@ref[maybe](Source/maybe.md)|Create a source that emits once the materialized @scala[`Promise`] @java[`CompletableFuture`] is completed with a value.|
|Source|<a name="queue"></a>@ref[queue](Source/queue.md)|Materialize a `SourceQueue` onto which elements can be pushed for emitting from the source. |
|Source|<a name="range"></a>@ref[range](Source/range.md)|Emit each integer in a range, with an option to take bigger steps than 1.|
|Source|<a name="repeat"></a>@ref[repeat](Source/repeat.md)|Stream a single object repeatedly|
|Source|<a name="single"></a>@ref[single](Source/single.md)|Stream a single object|
|Source|<a name="repeat"></a>@ref[repeat](Source/repeat.md)|Stream a single object repeatedly.|
|Source|<a name="single"></a>@ref[single](Source/single.md)|Stream a single object once.|
|Source|<a name="tick"></a>@ref[tick](Source/tick.md)|A periodical repetition of an arbitrary object.|
|Source|<a name="unfold"></a>@ref[unfold](Source/unfold.md)|Stream the result of a function as long as it returns a @scala[`Some`] @java[non empty `Optional`].|
|Source|<a name="unfoldasync"></a>@ref[unfoldAsync](Source/unfoldAsync.md)|Just like `unfold` but the fold function returns a @scala[`Future`] @java[`CompletionStage`].|