Threading & Time (std.thread, std.time)
Core standard library modules for concurrent execution and timestamp tracking. In Flame, code executes at the top level without needing a wrapper main function.
Time Tracking (std.time)
Section titled “Time Tracking (std.time)”Retrieve accurate system epoch timestamps in seconds or milliseconds:
import std.time
// Get current UNIX timestamp in secondslet secs = time.now().toSeconds()println($"Current Seconds: {secs}")
// Get current high-resolution UNIX timestamp objectlet now = time.now()println($"Timestamp in Milliseconds: {now.toMillis()}")
// Parse an RFC3339 or RFC2822 date string into a Timestamplet parsed = time.parse("2026-08-10T08:00:00Z")println($"Parsed Timestamp Millis: {parsed.toMillis()}")Timestamp Manipulation
Section titled “Timestamp Manipulation”Since timestamps are returned as Timestamp objects in Flame, you can easily access milliseconds or string representations.
import std.time
let now = time.now()
// Extract componentsprintln($"Millis: {now.toMillis()}")println($"Seconds: {now.toSeconds()}")println($"String: {now.toString()}")Concurrency & Channels (std.thread)
Section titled “Concurrency & Channels (std.thread)”Manage thread execution, sleep durations, and pass messages cleanly across concurrent threads using channels:
import std.thread
// Display the current OS thread identifierprintln($"Active thread ID: {thread.id()}")
// Pause execution of the current thread for 200 millisecondsthread.sleep(200)
// Yield execution time back to the operating system schedulerthread.yield()
// Create an asynchronous communication channellet (tx, rx) = thread.channel()
// Send and receive messages across thread channelstx.send("Message across channel!")let received = rx.recv()println($"Received: {received}")API Summary Tables
Section titled “API Summary Tables”Time (std.time)
Section titled “Time (std.time)”| Method | Arguments | Returns | Description |
|---|---|---|---|
time.now |
None | Timestamp |
Returns the current UTC time as a Timestamp object. |
time.parse |
date_string: String |
Timestamp |
Parses an ISO-8601 or RFC-3339 string into a Timestamp. |
time.fromMillis |
milliseconds: Int |
Timestamp |
Creates a Timestamp from Unix epoch milliseconds. |
time.fromSeconds |
seconds: Int |
Timestamp |
Creates a Timestamp from Unix epoch seconds. |
time.instant |
None | Instant |
Returns a monotonic point in time suitable for measuring elapsed durations. |
Timestamp Methods (Timestamp)
Section titled “Timestamp Methods (Timestamp)”The Timestamp object provides the following native methods:
| Method | Arguments | Returns | Description |
|---|---|---|---|
.toMillis() |
None | Int |
Returns the UNIX epoch milliseconds. |
.toSeconds() |
None | Int |
Returns the UNIX epoch seconds. |
.toString() |
None | String |
Returns the human readable UTC date time string. |
Threading (std.thread)
Section titled “Threading (std.thread)”| Method | Arguments | Returns | Description |
|---|---|---|---|
thread.sleep |
ms: Int |
Nil |
Suspends thread execution for the specified number of milliseconds. |
thread.id |
None | String |
Returns a formatted string representation of the active thread ID. |
thread.yield |
None | Nil |
Yields the processor, allowing other threads on the OS to run. |
thread.channel |
None | Tuple<Sender, Receiver> |
Creates a multi-producer, single-consumer communication channel. |
thread.spawn |
callback: Function |
ThreadHandler |
Spawns a background concurrent execution thread. |
