Movatterモバイル変換


[0]ホーム

URL:


Scala 3
3.7.4
LearnInstallPlaygroundFind A LibraryCommunityBlog
Scala 3
LearnInstallPlaygroundFind A LibraryCommunityBlog
DocsAPI
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL
Scala 3/scala/scala.concurrent/scala.concurrent.duration

scala.concurrent.duration

Members list

Type members

Classlikes

caseclassDeadline extendsOrdered[Deadline]

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

This class stores a deadline, as obtained viaDeadline.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 methodshasTimeLeft andtimeLeft. All durations are measured according toSystem.nanoTime; this does not take into account changes to the system clock (such as leap seconds).

Attributes

Companion
object
Source
Deadline.scala
Supertypes
traitProduct
traitEquals
classObject
traitMatchable
classAny
Show all
objectDeadline

Attributes

Companion
class
Source
Deadline.scala
Supertypes
classObject
traitMatchable
classAny
Self type
final implicitclassDoubleMult(f:Double) extendsAnyVal

Attributes

Source
package.scala
Supertypes
classAnyVal
traitMatchable
classAny
objectDuration

Attributes

Companion
class
Source
Duration.scala
Supertypes
classObject
traitMatchable
classAny
Self type
sealed abstractclassDuration extendsSerializable,Ordered[Duration]

This class is not meant as a general purpose representation of time, it is optimized for the needs ofscala.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 ofscala.concurrent.

Basic Usage

Examples:

import scala.concurrent.duration._val duration = Duration(100, MILLISECONDS)val duration = Duration(100, "millis")duration.toNanosduration < 1.secondduration <= Duration.Inf

Invoking inexpressible conversions (like callingtoSeconds 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 millisval d2 = d * 2.5val 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 tojava.lang.Double when it comes to infinite or undefined values

The conversion between Duration and Double is done usingDuration.toUnit (with unit NANOSECONDS) andDuration.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, includingDuration.Inf.

Attributes

Companion
object
Source
Duration.scala
Supertypes
classObject
traitMatchable
classAny
Show all
Known subtypes

Attributes

Companion
object
Source
DurationConversions.scala
Supertypes
classAny
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
Supertypes
classObject
traitMatchable
classAny
Self type
final implicitclassDurationDouble(d:Double) extendsAnyVal,DurationConversions

Attributes

Source
package.scala
Supertypes
final implicitclassDurationInt(n:Int) extendsAnyVal,DurationConversions

Attributes

Source
package.scala
Supertypes
final implicitclassDurationLong(n:Long) extendsAnyVal,DurationConversions

Attributes

Source
package.scala
Supertypes

Attributes

Companion
class
Source
Duration.scala
Supertypes
classObject
traitMatchable
classAny
Self type
finalclassFiniteDuration(vallength:Long,valunit:TimeUnit) extendsDuration

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
Supertypes
classDuration
classObject
traitMatchable
classAny
Show all
final implicitclassIntMult(i:Int) extendsAnyVal

Attributes

Source
package.scala
Supertypes
classAnyVal
traitMatchable
classAny
final implicitclassLongMult(i:Long) extendsAnyVal

Attributes

Source
package.scala
Supertypes
classAnyVal
traitMatchable
classAny
objectfromNow

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
Supertypes
classObject
traitMatchable
classAny
Self type
fromNow.type
objectspan

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
Supertypes
classObject
traitMatchable
classAny
Self type
span.type

Types

Attributes

Source
package.scala

Value members

Concrete fields

finalvalDAYS:TimeUnit

Attributes

Source
package.scala
finalvalHOURS:TimeUnit

Attributes

Source
package.scala

Attributes

Source
package.scala

Attributes

Source
package.scala

Attributes

Source
package.scala

Attributes

Source
package.scala

Attributes

Source
package.scala

Implicits

Implicits

final implicitdefDoubleMult(f:Double):DoubleMult

Attributes

Source
package.scala

Attributes

Source
package.scala
final implicitdefDurationInt(n:Int):DurationInt

Attributes

Source
package.scala
final implicitdefDurationLong(n:Long):DurationLong

Attributes

Source
package.scala
final implicitdefIntMult(i:Int):IntMult

Attributes

Source
package.scala
final implicitdefLongMult(i:Long):LongMult

Attributes

Source
package.scala

Attributes

Source
package.scala

Attributes

Source
package.scala
In this article
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL

[8]ページ先頭

©2009-2025 Movatter.jp