@@ -675,6 +675,30 @@ final class Stream[+F[_], +O] private[fs2] (private[fs2] val underlying: Pull[F,
675
675
def meteredStartImmediately [F2 [x] >: F [x]: Temporal ](rate : FiniteDuration ): Stream [F2 , O ] =
676
676
(Stream .emit(()) ++ Stream .fixedRate[F2 ](rate)).zipRight(this )
677
677
678
+ /** Waits the specified `delay` between each event.
679
+ *
680
+ * The resulting stream emits the same elements from `this` stream,
681
+ * but split into singleton chunks. Between each chunk (element) it
682
+ * adds a pause of a fixed `delay` duration.
683
+ *
684
+ * This method differs in the timing of elements from [[metered ]].
685
+ * The [[metered ]] combinator takes a "schedule" for elements to be released,
686
+ * and before each element introduces just the necessary delay to hit that time.
687
+ * To do so, it deducts from the pause any delay caused by other effects
688
+ * in the stream, or the pauses the stream consumer takes while pulling.
689
+ * This method, instead, simply introduced a fixed sleep time between elements,
690
+ * irrespective of other pauses in the stream or the consumer.
691
+ *
692
+ * Starts immediately, same as [[meteredStartImmediately ]]
693
+ * unless parameter `startImmediately` is set to false.
694
+ */
695
+ def spaced [F2 [x] >: F [x]: Temporal ](
696
+ delay : FiniteDuration ,
697
+ startImmediately : Boolean = true
698
+ ): Stream [F2 , O ] =
699
+ ((if (startImmediately) Stream .emit(()) else Stream .empty) ++ Stream .fixedDelay[F2 ](delay))
700
+ .zipRight(this )
701
+
678
702
/** Logs the elements of this stream as they are pulled.
679
703
*
680
704
* By default, `toString` is called on each element and the result is printed
0 commit comments