SlowIterator

tinyscalautils.timing.sleep$package.SlowIterator
object SlowIterator

Adds a slow method to iterators.

Attributes

Source
sleep.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Extensions

Extensions

extension [A](source: Iterator[A])
def slow(seconds: Double, delayedElements: Int): Iterator[A]

Slows down the iterator.

Slows down the iterator.

This method returns an iterator in which method next invokes sleep to slow it down. The number of elements being slowed down can be chosen: more means a smoother iterator, less means fewer calls to sleep overall. If the iterator has more elements than the specified number, the remaining elements are produced without delay. If the iterator has fewer elements, method hasNext is delayed before returning false at the end of the iteration. Overall, stepping through the entire iterator adds the entire specified delay (assuming the iterator does end). The default value 32 is entirely arbitrary.

The time taken by the underlying iterator to produce its values is not taken into account. Delays are added to that time. Therefore, stepping through the entire iterator takes more time than the specified delay.

The purpose of this method is to slow down demos. The actual time taken by an iterator to produce all its values is not guaranteed to be very precise (i.e., in the order of seconds, not milliseconds).

Attributes

Source
sleep.scala