time
UTC instants, calendar dates, durations, sleeping, and scoped timeouts.
Everything here is UTC. There is no local-time or time-zone support, and no
way to attach an offset to a DateTime.
Duration arguments
Wherever a duration is accepted, it may be given either as a
Duration or as a plain number of seconds --
Int or Float. Numeric durations must
be non-negative, and floating-point ones finite.
Types
| Type | Description |
|---|---|
Date |
A calendar date, with no time of day and no time zone. |
DateTime |
A UTC instant, held as Unix nanoseconds. |
Duration |
A signed time span, with nanosecond precision. |
Month |
A calendar month. |
Weekday |
A day of the week. |
Functions
sleep duration
Suspends the current strand.
Parameters
| Name | Type | Description |
|---|---|---|
duration |
(Duration | Int | Float) |
How long to sleep. See Duration arguments. |
Errors
| Exception | Condition |
|---|---|
TypeError |
duration is not a duration or number |
RuntimeError |
The duration is negative, or a non-finite float |
Example
timeout[R] duration block -> R
Runs a block under a scoped timeout.
When the duration elapses, the block's strand is interrupted. The interrupt is delivered at the next suspend or interrupt-check point, so a block that never reaches one runs to completion regardless. The timeout is scoped: it is torn down when the block returns, however it exits.
Parameters
| Name | Type | Description |
|---|---|---|
duration |
(Duration | Int | Float) |
How long the block may run. See Duration arguments. |
block |
(() -> R) |
Block to run. |
Errors
| Exception | Condition |
|---|---|
TypeError |
duration is not a duration or number |
RuntimeError |
The duration is negative, or a non-finite float |
TimedOutError |
The timeout elapsed before the block completed |