You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: sips/pending/_posts/2012-01-21-futures-promises.md
+22-15Lines changed: 22 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -659,40 +659,47 @@ for clients
659
659
for library writers
660
660
-->
661
661
662
-
663
662
## Utilities
664
663
665
-
To simplify the handling of time units, Akka's `Duration`
666
-
type should be added to the `scala.util` package.
664
+
To simplify handling of time in concurrent applications `scala.concurrent`
665
+
will introduce a `Duration` abstraction. Duration is not supposed be yet another
666
+
general time abstraction. It is meant to be used with concurrency libraries and
667
+
will reside in `scala.concurrent.util` package.
668
+
669
+
`Duration` is the base class representing length of time. It can be either finite or infinite.
670
+
Finite duration is represented with `FiniteDuration` class which is constructed from `Long` length and
671
+
`java.util.concurrent.TimeUnit`. Infinite durations, also extended from `Duration`,
672
+
exist in only two instances , `Duration.Inf` and `Duration.MinusInf`. Library also
673
+
provides several `Duration` subclasses for implicit conversion purposes and those should
674
+
not be used.
667
675
668
-
`Duration` is a base class representing a time interval. An instance
669
-
can either be a `FiniteDuration` that contains a length and a
670
-
`TimeUnit`, or an infinite duration (`Duration.Inf` or
671
-
`Duration.MinusInf`). `Duration` contains methods that allow:
676
+
Abstract `Duration` contains methods that allow :
672
677
673
-
1. Conversion to different time units (`toNanos`, `toMicros`, `toMillis`, `toSeconds`, `toMinutes`, `toHours`, `toDays` and `toUnit(unit: TimeUnit)`).
678
+
1. Conversion to different time units (`toNanos`, `toMicros`, `toMillis`,
679
+
`toSeconds`, `toMinutes`, `toHours`, `toDays` and `toUnit(unit: TimeUnit)`).
674
680
2. Comparison of durations (`<`, `<=`, `>` and `>=`).
675
681
3. Arithmetic operations (`+`, `-`, `*`, `/` and `unary_-`).
676
-
4. Minimum and maximum between this duration and the one supplied in the argument (`min`, `max`).
682
+
4. Minimum and maximum between `this` duration and the one supplied in the argument (`min`, `max`).
677
683
5. Check if the duration is finite (`finite_?`).
678
684
679
-
Instances of `Duration` should be created using factory methods in the companion object. `Duration` instances can be instantiated in the following ways:
685
+
`Duration` instances can be instantiated in the following ways:
680
686
681
687
1. Implicitly from types `Int` and `Long`. For example `val d = 100 millis`.
682
-
2. By passing a length and a `java.util.concurrent.TimeUnit`. For example `val d = Duration(100, MILLISECONDS)`.
683
-
3. By parsing strings that represent a time period. For example `val d = Duration("1.2 µs")`.
684
-
688
+
2. By passing a `Long` length and a `java.util.concurrent.TimeUnit`.
689
+
For example `val d = Duration(100, MILLISECONDS)`.
690
+
3. By parsing a string that represent a time period. For example `val d = Duration("1.2 µs")`.
691
+
685
692
Examples:
686
693
687
-
import scala.util.Duration
694
+
import scala.concurrent.util.Duration
688
695
import java.util.concurrent.TimeUnit._
689
696
690
697
val d1 = Duration(100, MILLISECONDS) // from Long and TimeUnit
691
698
val d2 = Duration(100, "millis") // from Long and String
692
699
val d3 = 100 millis // implicitly from Long, Int or Double
693
700
val d4 = Duration("1.2 µs") // from String
694
701
695
-
Duration also provides `unapply` methods so it can be pattern matched against and constructed as follows:
702
+
Duration also provides `unapply` methods so it can be used in pattern matching constructs as follows:
0 commit comments