gossamer

Top-level cross-runtime APIs: timers, base64, microtask scheduling, and navigator info. Domain-specific APIs live in submodules (see gossamer/url, gossamer/stream/readable_stream, gossamer/fetch_extra, etc.).

Values

pub fn clear_interval(id: Int) -> Nil

Cancels a repeating timer previously scheduled with set_interval.

pub fn clear_timeout(id: Int) -> Nil

Cancels a one-shot timer previously scheduled with set_timeout.

pub fn decode_base64(encoded: String) -> Result(String, Nil)

Decodes a base64-encoded string. Returns an error if the string is not valid base64. Equivalent to JavaScript’s atob.

pub fn encode_base64(data: String) -> Result(String, Nil)

Encodes a binary string as base64. Returns an error if data contains code points beyond 0xFF (use gleam/bit_array.base64_encode for arbitrary bytes). Equivalent to JavaScript’s btoa.

pub fn hardware_concurrency() -> Int

Returns the number of logical processors available to the runtime. Useful for sizing worker pools. Some browsers cap this value for fingerprinting protection. Equivalent to JavaScript’s navigator.hardwareConcurrency.

pub fn queue_microtask(callback: fn() -> a) -> Nil

Schedules callback to run as a microtask — after the current execution stack empties but before returning control to the event loop.

pub fn set_interval(
  delay: duration.Duration,
  callback: fn() -> a,
) -> Int

Schedules callback to run repeatedly every delay. Returns an id that can be passed to clear_interval to cancel. Negative durations are treated as zero.

pub fn set_timeout(
  delay: duration.Duration,
  callback: fn() -> a,
) -> Int

Sets a timer which executes callback once after delay elapses. Returns an id that can be passed to clear_timeout to cancel. Negative durations are treated as zero.

pub fn user_agent() -> String

Returns the runtime’s user agent string (e.g., browser identity, Deno/Node version). Equivalent to JavaScript’s navigator.userAgent.

Search Document