Skip to content

Commit 00c5218

Browse files
author
Vojin Jovanovic
committed
Updating utilities section in sip 14.
1 parent 415a185 commit 00c5218

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

sips/pending/_posts/2012-01-21-futures-promises.md

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -659,40 +659,47 @@ for clients
659659
for library writers
660660
-->
661661

662-
663662
## Utilities
664663

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.
667675

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 :
672677

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)`).
674680
2. Comparison of durations (`<`, `<=`, `>` and `>=`).
675681
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`).
677683
5. Check if the duration is finite (`finite_?`).
678684

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:
680686

681687
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+
685692
Examples:
686693

687-
import scala.util.Duration
694+
import scala.concurrent.util.Duration
688695
import java.util.concurrent.TimeUnit._
689696

690697
val d1 = Duration(100, MILLISECONDS) // from Long and TimeUnit
691698
val d2 = Duration(100, "millis") // from Long and String
692699
val d3 = 100 millis // implicitly from Long, Int or Double
693700
val d4 = Duration("1.2 µs") // from String
694701

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:
696703

697704
val Duration(length, unit) = 5 millis
698705

0 commit comments

Comments
 (0)