glixir

glixir - Enhanced with Subject support for proper message passing

This module provides a unified API for working with OTP processes from Gleam. Now includes registry support for Subject lookup.

Types

pub type Agent =
  agent.Agent
pub type AgentError =
  agent.AgentError

Values

pub fn agent_pid(agent: agent.Agent) -> process.Pid

Get the PID of an Agent

pub fn call_genserver(
  server: genserver.GenServer,
  request: a,
) -> Result(b, genserver.GenServerError)

Send a synchronous call to the GenServer (5s timeout)

pub fn call_genserver_named(
  name: String,
  request: a,
) -> Result(b, genserver.GenServerError)

Call a named GenServer

pub fn call_genserver_timeout(
  server: genserver.GenServer,
  request: a,
  timeout: Int,
) -> Result(b, genserver.GenServerError)

Send a synchronous call with custom timeout

pub fn cast_agent(agent: agent.Agent, fun: fn(a) -> a) -> Nil

Update the Agent state asynchronously

pub fn cast_genserver(
  server: genserver.GenServer,
  request: a,
) -> Result(Nil, genserver.GenServerError)

Send an asynchronous cast to the GenServer

pub fn cast_genserver_named(
  name: String,
  request: a,
) -> Result(Nil, genserver.GenServerError)

Cast to a named GenServer

pub fn child_spec(
  id id: String,
  module module: String,
  function function: String,
  args args: List(dynamic.Dynamic),
) -> supervisor.SimpleChildSpec

Create a child specification

pub fn count_children(
  supervisor_instance: supervisor.Supervisor,
) -> supervisor.ChildCounts

Count children by status

pub fn delete_child(
  supervisor_instance: supervisor.Supervisor,
  child_id: String,
) -> Result(Nil, supervisor.ChildOperationError)

Delete a child specification from the supervisor

pub fn genserver_pid(server: genserver.GenServer) -> process.Pid

Get the PID of a GenServer

pub fn get_agent(
  agent: agent.Agent,
  fun: fn(a) -> b,
  decoder: decode.Decoder(b),
) -> Result(b, agent.AgentError)

Get the current state from an Agent

pub fn get_agent_timeout(
  agent: agent.Agent,
  fun: fn(a) -> b,
  timeout: Int,
  decoder: decode.Decoder(b),
) -> Result(b, agent.AgentError)

Get with custom timeout

pub fn get_and_update_agent(
  agent: agent.Agent,
  fun: fn(a) -> #(b, a),
  decoder: decode.Decoder(b),
) -> Result(b, agent.AgentError)

Get and update in one operation

pub fn get_genserver_state(
  server: genserver.GenServer,
) -> Result(dynamic.Dynamic, genserver.GenServerError)

Get state from a GenServer

pub fn lookup_genserver(
  name: String,
) -> Result(genserver.GenServer, genserver.GenServerError)

Look up a GenServer by registered name

pub fn lookup_subject(
  registry_name: String,
  key: String,
) -> Result(process.Subject(message), registry.RegistryError)

Look up a Subject by key in the registry

pub fn main() -> Nil

Main function for when glixir is run directly (demo/testing)

pub fn ping_genserver(
  server: genserver.GenServer,
) -> Result(dynamic.Dynamic, genserver.GenServerError)

Ping a GenServer (returns :pong if successful)

pub fn register_subject(
  registry_name: String,
  key: String,
  subject: process.Subject(message),
) -> Result(Nil, registry.RegistryError)

Register a Subject with a key in the registry

pub fn restart_child(
  supervisor_instance: supervisor.Supervisor,
  child_id: String,
) -> Result(process.Pid, supervisor.ChildOperationError)

Restart a child process

pub fn start_agent(
  initial_fun: fn() -> a,
) -> Result(agent.Agent, agent.AgentError)

Start a new Agent with initial state

pub fn start_agent_named(
  name: String,
  initial_fun: fn() -> a,
) -> Result(agent.Agent, agent.AgentError)

Start an Agent with a name

pub fn start_child(
  supervisor_instance: supervisor.Supervisor,
  spec: supervisor.SimpleChildSpec,
) -> Result(process.Pid, String)

Start a child process in the supervisor

pub fn start_genserver(
  module: String,
  args: a,
) -> Result(genserver.GenServer, genserver.GenServerError)

Start a GenServer using Module.start_link/1

pub fn start_genserver_named(
  module: String,
  name: String,
  args: a,
) -> Result(genserver.GenServer, genserver.GenServerError)

Start a named GenServer

pub fn start_registry(
  name: String,
) -> Result(registry.Registry, registry.RegistryError)

Start a unique registry for Subject lookup

pub fn start_simple_genserver(
  module: String,
  initial_state: String,
) -> Result(genserver.GenServer, genserver.GenServerError)

Start a simple GenServer with one argument

pub fn start_supervisor(
  ,
) -> Result(supervisor.Supervisor, supervisor.SupervisorError)

Start a supervisor with default options

pub fn start_supervisor_named(
  name: String,
  additional_options: List(#(String, dynamic.Dynamic)),
) -> Result(supervisor.Supervisor, supervisor.SupervisorError)

Start a named supervisor using DynamicSupervisor

pub fn start_supervisor_simple(
  ,
) -> Result(supervisor.Supervisor, supervisor.SupervisorError)

Start a simple supervisor with defaults

pub fn stop_agent(
  agent: agent.Agent,
) -> Result(Nil, agent.AgentError)

Stop an Agent

pub fn stop_genserver(
  server: genserver.GenServer,
) -> Result(Nil, genserver.GenServerError)

Stop a GenServer gracefully

pub fn supervisor_spec(
  id: String,
  module: String,
  args: List(dynamic.Dynamic),
) -> supervisor.SimpleChildSpec

Create a supervisor child spec

pub fn terminate_child(
  supervisor_instance: supervisor.Supervisor,
  child_id: String,
) -> Result(Nil, supervisor.ChildOperationError)

Terminate a child process

pub fn unregister_subject(
  registry_name: String,
  key: String,
) -> Result(Nil, registry.RegistryError)

Unregister a Subject from the registry

pub fn update_agent(
  agent: agent.Agent,
  fun: fn(a) -> a,
) -> Result(Nil, agent.AgentError)

Update the Agent state synchronously

pub fn which_children(
  supervisor_instance: supervisor.Supervisor,
) -> List(supervisor.ChildInfoResult)

Get list of child processes

pub fn worker_spec(
  id: String,
  module: String,
  args: List(dynamic.Dynamic),
) -> supervisor.SimpleChildSpec

Create a simple worker child spec with defaults

Search Document