Trait providing four implicit conversions that allow you to specify spans of time
by invoking "units" methods such as millis
, seconds
, and minutes
on Int
, Long
, Float
, and Double
.
This trait enables you to specify a span of time in a clear, boilerplate-free way when you
need to provide an instance of Span
. This
can be used, for example, with the failAfter
method of trait
Timeouts
or the timeLimit
field of trait
TimeLimitedTests
. It can also be used to specify
timeouts when using traits Eventually
,
Futures
,
Waiter
. Here are examples of each unit enabled by this trait:
Int
|
Long
|
Float
|
Double
|
---|---|---|---|
1 nanosecond | 1L nanosecond | 1.0F nanosecond | 1.0 nanosecond |
100 nanoseconds | 100L nanoseconds | 99.8F nanoseconds | 99.8 nanoseconds |
1 microsecond | 1L microsecond | 1.0F microsecond | 1.0 microsecond |
100 microseconds | 100L microseconds | 99.8F microseconds | 99.8 microseconds |
1 millisecond | 1L millisecond | 1.0F millisecond | 1.0 millisecond |
100 milliseconds | 100L milliseconds | 99.8F milliseconds | 99.8 milliseconds |
100 millis | 100L millis | 99.8F millis | 99.8 millis |
1 second | 1L second | 1.0F second | 1.0 second |
100 seconds | 100L seconds | 99.8F seconds | 99.8 seconds |
1 minute | 1L minute | 1.0F minute | 1.0 minute |
100 minutes | 100L minutes | 99.8F minutes | 99.8 minutes |
1 hour | 1L hour | 1.0F hour | 1.0 hour |
100 hours | 100L hours | 99.8F hours | 99.8 hours |
1 day | 1L day | 1.0F day | 1.0 day |
100 days | 100L days | 99.8F days | 99.8 days |
This trait is not the default way to specify Span
s for two reasons. First, it adds
four implicits, which would give the compiler more work to do and may conflict with other implicits the
user has in scope. Instead, Span
provides a clear, concise default way to specify time
spans that requires no implicits. Here's an example:
Span(1, Second)
If you already have implicit conversions in scope that provide a similar syntax sugar for expression
time spans, you can use that by providing an implicit conversion from the result of those expressions
to Span
. Note that because of implicit conversions in the Span
companion object,
you can use a scala.concurrent.duration.Duration
(including in its "sugary" form) where
a Span
is needed, and vice versa.
- Companion:
- object
Type members
Classlikes
Class containing methods that return a Span
time value calculated from the
Double
value passed to the FloatingGrainOfTime
constructor.
Class containing methods that return a Span
time value calculated from the
Double
value passed to the FloatingGrainOfTime
constructor.
- Value parameters:
- value
the value to be converted
Class containing methods that return a Span
time value calculated from the
Long
value passed to the GrainOfTime
constructor.
Class containing methods that return a Span
time value calculated from the
Long
value passed to the GrainOfTime
constructor.
- Value parameters:
- value
the value to be converted
Implicits
Implicits
Implicit conversion that adds time units methods to Double
s.
Implicit conversion that adds time units methods to Double
s.
- Value parameters:
- d:
the
Double
to which to add time units methods
- Returns:
a
FloatingGrainOfTime
wrapping the passedDouble
Implicit conversion that adds time units methods to Float
s.
Implicit conversion that adds time units methods to Float
s.
- Value parameters:
- f:
the
Float
to which to add time units methods
- Returns:
a
FloatingGrainOfTime
wrapping the passedFloat
Implicit conversion that adds time units methods to Int
s.
Implicit conversion that adds time units methods to Int
s.
- Value parameters:
- i:
the
Int
to which to add time units methods
- Returns:
a
GrainOfTime
wrapping the passedInt