Skip to content

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.


Retrieve accurate system epoch timestamps in seconds or milliseconds:

import std.time
// Get current UNIX timestamp in seconds
let secs = time.now().toSeconds()
println($"Current Seconds: {secs}")
// Get current high-resolution UNIX timestamp object
let now = time.now()
println($"Timestamp in Milliseconds: {now.toMillis()}")
// Parse an RFC3339 or RFC2822 date string into a Timestamp
let parsed = time.parse("2026-08-10T08:00:00Z")
println($"Parsed Timestamp Millis: {parsed.toMillis()}")

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 components
println($"Millis: {now.toMillis()}")
println($"Seconds: {now.toSeconds()}")
println($"String: {now.toString()}")

Manage thread execution, sleep durations, and pass messages cleanly across concurrent threads using channels:

import std.thread
// Display the current OS thread identifier
println($"Active thread ID: {thread.id()}")
// Pause execution of the current thread for 200 milliseconds
thread.sleep(200)
// Yield execution time back to the operating system scheduler
thread.yield()
// Create an asynchronous communication channel
let (tx, rx) = thread.channel()
// Send and receive messages across thread channels
tx.send("Message across channel!")
let received = rx.recv()
println($"Received: {received}")

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.

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