tinyscalautils.timing

Members list

Type members

Classlikes

object SlowIterator

Adds a slow method to iterators.

Adds a slow method to iterators.

Attributes

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

Adds a slow method to streams.

Adds a slow method to streams.

Attributes

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

Adds a slow method to sources.

Adds a slow method to sources.

Attributes

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

Value members

Concrete methods

def callFor[A, S](seconds: Double)(start: S)(step: S => Option[(A, S)])(using Timer): (Seq[A], Boolean)

Repeated invocations of step with a time bound. The function is repeatedly invoked on the "state" part of its previous output until it returns None or the timeout has been reached. The "value" part of the pair is collected into a sequence.

Repeated invocations of step with a time bound. The function is repeatedly invoked on the "state" part of its previous output until it returns None or the timeout has been reached. The "value" part of the pair is collected into a sequence.

Value parameters

seconds

a timeout in seconds; if it is negative, step is not invoked at all; it it is zero, step is invoked exactly once.

start

an initial state on which to execute step.

step

the stepping function

Attributes

Returns

a pair: a sequence of values produced by step and a flag that indicates normal termination (no timeout).

Since

1.2

Note

The stepping function is run in the thread that invokes callFor. No attempt is made to interrupt the thread inside step.

Source
runFor.scala
def callFor[A, S](seconds: Double)(start: S)(step: S => (A, Option[S]))(using Timer): (Seq[A], Boolean)

Repeated invocations of step with a time bound. The function is repeatedly invoked on the "state" part of its previous output until it returns None or the timeout has been reached. The "value" part of the pair is collected into a sequence.

Repeated invocations of step with a time bound. The function is repeatedly invoked on the "state" part of its previous output until it returns None or the timeout has been reached. The "value" part of the pair is collected into a sequence.

Value parameters

seconds

a timeout in seconds; if it is negative, step is not invoked at all; it it is zero, step is invoked exactly once.

start

an initial state on which to execute step.

step

the stepping function

Attributes

Returns

a pair: a sequence of values produced by step and a flag that indicates normal termination (no timeout).

Since

1.2

Note

The stepping function is run in the thread that invokes callFor. No attempt is made to interrupt the thread inside step.

Source
runFor.scala
def callFor[A](seconds: Double)(start: A)(step: A => Option[A])(using Timer): (Seq[A], Boolean)

Repeated invocations of step with a time bound. The function is repeatedly invoked on its previous output until it returns None or the timeout has been reached. The returned values are collected into a sequence.

Repeated invocations of step with a time bound. The function is repeatedly invoked on its previous output until it returns None or the timeout has been reached. The returned values are collected into a sequence.

Value parameters

seconds

a timeout in seconds; if it is negative, step is not invoked at all; it it is zero, step is invoked exactly once.

start

an initial state on which to execute step.

step

the stepping function

Attributes

Returns

a pair: a sequence of values produced by step and a flag that indicates normal termination (no timeout).

Since

1.2

Note

The stepping function is run in the thread that invokes callFor. No attempt is made to interrupt the thread inside step.

Source
runFor.scala
inline def delay[A](seconds: Double, start: Long)(inline code: A): A

Adds sleep time so code takes up specified duration.

Adds sleep time so code takes up specified duration.

This method does not throw InterruptedException. If the thread is interrupted, the sleeping stops and the thread is left interrupted.

If the code fails, the exception is thrown after the specified delay.

An argument can be used to specify the starting clock, as per getTime; this is useful when a preliminary computation needs to be performed before sleeping. The value of this argument is assumed to be in the past. (In particular, delaying by a negative amount of time does not delay, independently from the start value.)

Value parameters

start

A starting point for sleep time, as per getTime.

Attributes

Since

1.0

Source
sleep.scala
inline def getTime(): Long

An alias for System.nanoTime.

An alias for System.nanoTime.

Attributes

Since

1.0

Source
timing.scala
inline def now(): Long

An alias for System.currentTimeMillis.

An alias for System.currentTimeMillis.

Attributes

Since

1.0

Source
timing.scala
def runFor[A](seconds: Double)(start: A)(step: A => Option[A])(using timer: Timer): Boolean

Repeated invocations of step with a time bound. The function is repeatedly invoked on its previous output until it returns None or the timeout has been reached.

Repeated invocations of step with a time bound. The function is repeatedly invoked on its previous output until it returns None or the timeout has been reached.

Value parameters

seconds

a timeout in seconds; if it is negative, step is not invoked at all; it it is zero, step is invoked exactly once.

start

an initial value on which to execute step.

step

the stepping function

Attributes

Returns

a flag that indicates normal termination (no timeout).

Since

1.2

Note

The stepping function is run in the thread that invokes runFor. No attempt is made to interrupt the thread inside step.

Source
runFor.scala
def runFor(seconds: Double)(step: () => Boolean)(using Timer): Boolean

Repeated invocations of step with a time bound. The function is repeatedly invoked for side effects until it returns false or the timeout has been reached.

Repeated invocations of step with a time bound. The function is repeatedly invoked for side effects until it returns false or the timeout has been reached.

Value parameters

seconds

a timeout in seconds; if it is negative, step is not invoked at all; it it is zero, step is invoked exactly once.

step

the stepping function

Attributes

Returns

a flag that indicates normal termination (no timeout).

Since

1.2

Note

The stepping function is run in the thread that invokes runFor. No attempt is made to interrupt the thread inside step.

Source
runFor.scala
def sleep(seconds: Double, start: Long): Unit

Pauses the calling thread for the specified amount of time.

Pauses the calling thread for the specified amount of time.

This method differs from Thread.sleep is several ways:

  • durations are specified in seconds as a floating point number.
  • the method never undershoots, as it sometimes happens with Thread.sleep on some platforms.
  • InterruptedException is not thrown; the thread is left interrupted instead.

An argument can be used to specify the starting clock, as per getTime; this is useful when a preliminary computation needs to be performed before sleeping. The value of this argument is assumed to be in the past. (In particular, delaying by a negative amount of time does not delay, independently from the start value.)

Value parameters

start

A starting point for sleep time, as per getTime.

Attributes

Since

1.0

Source
sleep.scala
inline def timeIt[A](inline code: A): (A, Double)

Executes code with timing.

Executes code with timing.

Attributes

Returns

the value produced by code, and a timing in seconds.

Since

1.0

Source
timing.scala
inline def timeOf[U](inline code: U): Double

Executes code with timing.

Executes code with timing.

Attributes

Returns

a timing for code, in seconds.

Since

1.0

Source
timing.scala

Givens

Givens

Adds a slow method to iterators.

Adds a slow method to iterators.

Attributes

Source
sleep.scala

Adds a slow method to streams.

Adds a slow method to streams.

Attributes

Source
sleep.scala

Adds a slow method to sources.

Adds a slow method to sources.

Attributes

Source
sleep.scala

Extensions

Extensions

extension [A](future: Future[A])

Adds duration (in seconds) to a future. Duration is calculated from the invocation of this method to the completion of the future.

Adds duration (in seconds) to a future. Duration is calculated from the invocation of this method to the completion of the future.

Attributes

Returns

a future of a pair (value, duration)

Since

1.0

Source
timing.scala
extension (seconds: Double)
def toNanos: Long

Multiplies the double value by 1e9, then rounds.

Multiplies the double value by 1e9, then rounds.

Attributes

Source
timing.scala