glixir
glixir - Unified OTP interface for Gleam, now type safe! Bounded, phantom-typed supervisors! No more runtime surprises.
Types
pub type Agent(state) =
agent.Agent(state)
pub type AgentError =
agent.AgentError
pub type ChildInfo(child_args, child_reply) =
supervisor.ChildInfo(child_args, child_reply)
pub type ChildOperationError =
supervisor.ChildOperationError
pub type ChildSpec(child_args, child_reply) =
supervisor.ChildSpec(child_args, child_reply)
pub type ChildStatus =
supervisor.ChildStatus
pub type ChildType =
supervisor.ChildType
pub type DynamicSupervisor(child_args, child_reply) =
supervisor.DynamicSupervisor(child_args, child_reply)
pub type GenServer(request, reply) =
genserver.GenServer(request, reply)
pub type GenServerError =
genserver.GenServerError
pub type KeyEncoder(key_type) =
fn(key_type) -> String
pub type MessageDecoder(message_type) =
fn(String) -> Result(message_type, String)
pub type MessageEncoder(message_type) =
fn(message_type) -> String
pub type PubSub(message_type) =
pubsub.PubSub(message_type)
pub type PubSubError =
pubsub.PubSubError
pub type Registry(key_type, message_type) =
registry.Registry(key_type, message_type)
pub type RegistryError =
registry.RegistryError
pub type RegistryKeys =
registry.RegistryKeys
pub type RestartStrategy =
supervisor.RestartStrategy
pub type StartChildResult(child_reply) =
supervisor.StartChildResult(child_reply)
pub type SupervisorError =
supervisor.SupervisorError
Values
pub fn agent_pid(agent: agent.Agent(a)) -> process.Pid
pub const atom_key_encoder: fn(atom.Atom) -> String
pub fn call_genserver(
server: genserver.GenServer(dynamic.Dynamic, reply),
request: dynamic.Dynamic,
decoder: decode.Decoder(reply),
) -> Result(reply, genserver.GenServerError)
pub fn call_genserver_named(
name: atom.Atom,
request: dynamic.Dynamic,
decoder: decode.Decoder(reply),
) -> Result(reply, genserver.GenServerError)
pub fn call_genserver_timeout(
server: genserver.GenServer(dynamic.Dynamic, reply),
request: dynamic.Dynamic,
timeout: Int,
decoder: decode.Decoder(reply),
) -> Result(reply, genserver.GenServerError)
pub fn cast_agent(agent: agent.Agent(a), fun: fn(a) -> a) -> Nil
pub fn cast_genserver(
server: genserver.GenServer(dynamic.Dynamic, reply),
request: dynamic.Dynamic,
) -> Result(Nil, genserver.GenServerError)
pub fn cast_genserver_named(
name: atom.Atom,
request: dynamic.Dynamic,
) -> Result(Nil, genserver.GenServerError)
pub fn child_spec(
id id: String,
module module: String,
function function: String,
args args: child_args,
restart restart: supervisor.RestartStrategy,
shutdown_timeout shutdown_timeout: Int,
child_type child_type: supervisor.ChildType,
) -> supervisor.ChildSpec(child_args, child_reply)
Build a bounded, type-safe child spec
pub fn count_dynamic_children(
sup: supervisor.DynamicSupervisor(child_args, child_reply),
) -> Result(supervisor.ChildCounts, String)
Get the count of dynamic children
pub const duplicate: registry.RegistryKeys
pub fn genserver_pid(
server: genserver.GenServer(dynamic.Dynamic, reply),
) -> process.Pid
pub fn get_agent(
agent: agent.Agent(a),
fun: fn(a) -> b,
decoder: decode.Decoder(b),
) -> Result(b, agent.AgentError)
pub fn get_agent_timeout(
agent: agent.Agent(a),
fun: fn(a) -> b,
timeout: Int,
decoder: decode.Decoder(b),
) -> Result(b, agent.AgentError)
pub fn get_all_dynamic_children(
sup: supervisor.DynamicSupervisor(child_args, child_reply),
) -> Result(List(process.Subject(child_reply)), String)
Get all child processes from a dynamic supervisor
pub fn get_and_update_agent(
agent: agent.Agent(a),
fun: fn(a) -> #(b, a),
decoder: decode.Decoder(b),
) -> Result(b, agent.AgentError)
pub fn get_genserver_state(
server: genserver.GenServer(dynamic.Dynamic, reply),
msg: dynamic.Dynamic,
decoder: decode.Decoder(reply),
) -> Result(reply, genserver.GenServerError)
pub const int_decoder: fn(String) -> Result(Int, String)
pub const int_encoder: fn(Int) -> String
pub const int_key_encoder: fn(Int) -> String
pub fn lookup_genserver(
name: atom.Atom,
) -> Result(
genserver.GenServer(dynamic.Dynamic, reply),
genserver.GenServerError,
)
pub fn lookup_subject(
registry_name: atom.Atom,
key: key_type,
encode_key: fn(key_type) -> String,
) -> Result(process.Subject(message_type), registry.RegistryError)
Look up a subject by typed key (requires key encoder)
pub fn lookup_subject_string(
registry_name: atom.Atom,
key: String,
) -> Result(process.Subject(message_type), registry.RegistryError)
SAFE: Look up a subject by string key (no dynamic atom creation) Use this for user-generated keys to avoid atom table exhaustion
pub const permanent: supervisor.RestartStrategy
pub fn ping_genserver(
server: genserver.GenServer(dynamic.Dynamic, reply),
msg: dynamic.Dynamic,
decoder: decode.Decoder(reply),
) -> Result(reply, genserver.GenServerError)
pub fn pubsub_broadcast(
pubsub_name: atom.Atom,
topic: String,
message: message_type,
encode: fn(message_type) -> String,
) -> Result(Nil, pubsub.PubSubError)
Broadcast a message to all subscribers
pub fn pubsub_start(
name: atom.Atom,
) -> Result(pubsub.PubSub(message_type), pubsub.PubSubError)
Start a phantom-typed PubSub system
pub fn pubsub_subscribe(
pubsub_name: atom.Atom,
topic: String,
gleam_module: String,
gleam_function: String,
) -> Result(Nil, pubsub.PubSubError)
Subscribe to a topic with message handling
pub fn pubsub_subscribe_with_registry_key(
pubsub_name: atom.Atom,
topic: String,
gleam_module: String,
gleam_function: String,
registry_key: String,
) -> Result(Nil, pubsub.PubSubError)
pub fn pubsub_unsubscribe(
pubsub_name: atom.Atom,
topic: String,
) -> Result(Nil, pubsub.PubSubError)
Unsubscribe from a topic
pub fn register_subject(
registry_name: atom.Atom,
key: key_type,
subject: process.Subject(message_type),
encode_key: fn(key_type) -> String,
) -> Result(Nil, registry.RegistryError)
Register a subject with a typed key (requires key encoder)
pub fn register_subject_string(
registry_name: atom.Atom,
key: String,
subject: process.Subject(message_type),
) -> Result(Nil, registry.RegistryError)
SAFE: Register a subject with string key (no dynamic atom creation) Use this for user-generated keys to avoid atom table exhaustion
pub const session_key_encoder: fn(String) -> String
pub fn start_agent(
state: fn() -> a,
) -> Result(agent.Agent(a), agent.AgentError)
pub fn start_dynamic_child(
sup: supervisor.DynamicSupervisor(child_args, child_reply),
spec: supervisor.ChildSpec(child_args, child_reply),
encode: fn(child_args) -> List(dynamic.Dynamic),
decode: fn(dynamic.Dynamic) -> Result(child_reply, String),
) -> supervisor.StartChildResult(child_reply)
Start a child process in the supervisor (requires encoder/decoder)
pub fn start_dynamic_supervisor() -> Result(
supervisor.DynamicSupervisor(child_args, child_reply),
supervisor.SupervisorError,
)
Start an unnamed dynamic supervisor
pub fn start_dynamic_supervisor_named(
name: atom.Atom,
) -> Result(
supervisor.DynamicSupervisor(child_args, child_reply),
supervisor.SupervisorError,
)
Start a named dynamic supervisor (you must always specify child_args, child_reply types)
pub fn start_dynamic_supervisor_named_safe(
name: String,
) -> Result(
supervisor.DynamicSupervisor(child_args, child_reply),
supervisor.SupervisorError,
)
pub fn start_genserver(
module: String,
args: dynamic.Dynamic,
) -> Result(
genserver.GenServer(dynamic.Dynamic, reply),
genserver.GenServerError,
)
pub fn start_genserver_named(
module: String,
name: atom.Atom,
args: dynamic.Dynamic,
) -> Result(
genserver.GenServer(dynamic.Dynamic, reply),
genserver.GenServerError,
)
pub fn start_registry(
name: atom.Atom,
) -> Result(
registry.Registry(key_type, message_type),
registry.RegistryError,
)
Start a phantom-typed unique registry (you must specify key_type, message_type)
pub fn start_registry_with_keys(
name: atom.Atom,
keys: registry.RegistryKeys,
) -> Result(
registry.Registry(key_type, message_type),
registry.RegistryError,
)
Start a registry with specific keys configuration
pub fn stop_agent(
agent: agent.Agent(a),
reason: atom.Atom,
) -> Result(Nil, agent.AgentError)
pub fn stop_genserver(
server: genserver.GenServer(dynamic.Dynamic, reply),
) -> Result(Nil, genserver.GenServerError)
pub const string_decoder: fn(String) -> Result(String, String)
pub const string_encoder: fn(String) -> String
pub const string_key_encoder: fn(String) -> String
pub const supervisor_child: supervisor.ChildType
pub const temporary: supervisor.RestartStrategy
pub fn terminate_dynamic_child(
sup: supervisor.DynamicSupervisor(child_args, child_reply),
child_pid: process.Pid,
) -> Result(Nil, String)
pub const transient: supervisor.RestartStrategy
pub const unique: registry.RegistryKeys
pub fn unregister_subject(
registry_name: atom.Atom,
key: key_type,
encode_key: fn(key_type) -> String,
) -> Result(Nil, registry.RegistryError)
Unregister a subject by typed key (requires key encoder)
pub fn unregister_subject_string(
registry_name: atom.Atom,
key: String,
) -> Result(Nil, registry.RegistryError)
SAFE: Unregister a subject by string key (no dynamic atom creation) Use this for user-generated keys to avoid atom table exhaustion
pub fn update_agent(
agent: agent.Agent(a),
fun: fn(a) -> a,
) -> Result(Nil, agent.AgentError)
pub const user_id_encoder: fn(Int) -> String
pub fn which_dynamic_children(
sup: supervisor.DynamicSupervisor(child_args, child_reply),
) -> List(dynamic.Dynamic)
Get all dynamic children of the supervisor
pub const worker: supervisor.ChildType