scala.concurrent.duration

Members list

Concise view

Type members

Classlikes

case class Deadline extends Ordered[Deadline]

This class stores a deadline, as obtained via Deadline.now or the duration DSL:

This class stores a deadline, as obtained via Deadline.now or the duration DSL:

import scala.concurrent.duration._
3.seconds.fromNow

Its main purpose is to manage repeated attempts to achieve something (like awaiting a condition) by offering the methods hasTimeLeft and timeLeft. All durations are measured according to System.nanoTime; this does not take into account changes to the system clock (such as leap seconds).

Attributes

Companion:
object
Source:
Deadline.scala
Graph
Supertypes
trait Product
trait Equals
class Object
trait Matchable
class Any
object Deadline

Attributes

Companion:
class
Source:
Deadline.scala
Graph
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
final implicit class DoubleMult(f: Double) extends AnyVal

Attributes

Source:
package.scala
Graph
Supertypes
class AnyVal
trait Matchable
class Any
object Duration

Attributes

Companion:
class
Source:
Duration.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
sealed abstract class Duration extends Serializable with Ordered[Duration]

This class is not meant as a general purpose representation of time, it is optimized for the needs of scala.concurrent.

Utility for working with java.util.concurrent.TimeUnit durations.

This class is not meant as a general purpose representation of time, it is optimized for the needs of scala.concurrent.

Basic Usage

Examples:

import scala.concurrent.duration._

val duration = Duration(100, MILLISECONDS)
val duration = Duration(100, "millis")

duration.toNanos
duration < 1.second
duration <= Duration.Inf

Invoking inexpressible conversions (like calling toSeconds on an infinite duration) will throw an IllegalArgumentException.

Implicits are also provided for Int, Long and Double. Example usage:

import scala.concurrent.duration._

val duration = 100.millis

The DSL provided by the implicit conversions always allows construction of finite durations, even for infinite Double inputs; use Duration.Inf instead.

Extractors, parsing and arithmetic are also included:

val d = Duration("1.2 µs")
val Duration(length, unit) = 5 millis
val d2 = d * 2.5
val d3 = d2 + 1.millisecond

Handling of Time Units

Calculations performed on finite durations always retain the more precise unit of either operand, no matter whether a coarser unit would be able to exactly express the same duration. This means that Duration can be used as a lossless container for a (length, unit) pair if it is constructed using the corresponding methods and no arithmetic is performed on it; adding/subtracting durations should in that case be done with care.

Correspondence to Double Semantics

The semantics of arithmetic operations on Duration are two-fold:

- exact addition/subtraction with nanosecond resolution for finite durations, independent of the summands' magnitude - isomorphic to java.lang.Double when it comes to infinite or undefined values

The conversion between Duration and Double is done using Duration.toUnit (with unit NANOSECONDS) and Duration.fromNanos(Double)

Ordering

The default ordering is consistent with the ordering of Double numbers, which means that Undefined is considered greater than all other durations, including Duration.Inf.

Attributes

Companion:
object
Source:
Duration.scala
Graph
Supertypes
Known subtypes

Attributes

Companion:
object
Source:
DurationConversions.scala
Graph
Supertypes
class Any
Known subtypes

This object just holds some cogs which make the DSL machine work, not for direct consumption.

This object just holds some cogs which make the DSL machine work, not for direct consumption.

Attributes

Companion:
trait
Source:
DurationConversions.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
final implicit class DurationDouble(d: Double) extends AnyVal with DurationConversions

Attributes

Source:
package.scala
Graph
Supertypes
final implicit class DurationInt(n: Int) extends AnyVal with DurationConversions

Attributes

Source:
package.scala
Graph
Supertypes
final implicit class DurationLong(n: Long) extends AnyVal with DurationConversions

Attributes

Source:
package.scala
Graph
Supertypes

Attributes

Companion:
class
Source:
Duration.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
final class FiniteDuration(val length: Long, val unit: TimeUnit) extends Duration

This class represents a finite duration.

This class represents a finite duration. Its addition and subtraction operators are overloaded to retain this guarantee statically. The range of this class is limited to +-(2^63-1)ns, which is roughly 292 years.

Attributes

Companion:
object
Source:
Duration.scala
Graph
Supertypes
final implicit class IntMult(i: Int) extends AnyVal

Attributes

Source:
package.scala
Graph
Supertypes
class AnyVal
trait Matchable
class Any
final implicit class LongMult(i: Long) extends AnyVal

Attributes

Source:
package.scala
Graph
Supertypes
class AnyVal
trait Matchable
class Any
object fromNow

This object can be used as closing token for declaring a deadline at some future point in time:

This object can be used as closing token for declaring a deadline at some future point in time:

import scala.concurrent.duration._

val deadline = 3 seconds fromNow

Attributes

Source:
package.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
fromNow.type
object span

This object can be used as closing token if you prefer dot-less style but do not want to enable language.postfixOps:

This object can be used as closing token if you prefer dot-less style but do not want to enable language.postfixOps:

import scala.concurrent.duration._

val duration = 2 seconds span

Attributes

Source:
package.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
span.type

Types

Attributes

Source:
package.scala

Value members

Concrete fields

final val DAYS: TimeUnit

Attributes

Source:
package.scala
final val HOURS: TimeUnit

Attributes

Source:
package.scala

Attributes

Source:
package.scala

Attributes

Source:
package.scala
final val MINUTES: TimeUnit

Attributes

Source:
package.scala

Attributes

Source:
package.scala
final val SECONDS: TimeUnit

Attributes

Source:
package.scala

Implicits

Implicits

final implicit def DoubleMult(f: Double): DoubleMult

Attributes

Source:
package.scala
final implicit def DurationDouble(d: Double): DurationDouble

Attributes

Source:
package.scala
final implicit def DurationInt(n: Int): DurationInt

Attributes

Source:
package.scala
final implicit def DurationLong(n: Long): DurationLong

Attributes

Source:
package.scala
final implicit def IntMult(i: Int): IntMult

Attributes

Source:
package.scala
final implicit def LongMult(i: Long): LongMult

Attributes

Source:
package.scala
implicit def durationToPair(d: Duration): (Long, TimeUnit)

Attributes

Source:
package.scala
implicit def pairIntToDuration(p: (Int, TimeUnit)): Duration

Attributes

Source:
package.scala

Attributes

Source:
package.scala