atomvm_gleam/avm_pubsub

Types

Errors from avm_pubsub / gen_server.

pub type Error {
  Failed
  NotSupported
  Badarg
  Timeout
  Other(String)
}

Constructors

  • Failed
  • NotSupported
  • Badarg
  • Timeout
  • Other(String)

Opaque handle for a running avm_pubsub gen_server (pid()).

pub type Server

Values

pub fn error_to_string(error: Error) -> String

Format an Error for logging.

pub fn publish(
  server: Server,
  topic: topic,
  term: term,
) -> Result(Int, Error)

Publish term on topic. Returns the number of matching subscribers notified.

Maps to upstream avm_pubsub:pub/3 (pub is a Gleam keyword).

See avm_pubsub:pub/3.

pub fn start() -> Result(Server, Error)

Start an unnamed avm_pubsub gen_server.

See avm_pubsub:start/0.

pub fn start_named(name: String) -> Result(Server, Error)

Start an avm_pubsub gen_server registered under a local atom name.

name is converted to an atom in the FFI (binary_to_atom/2), matching other modules that accept Gleam String names.

See avm_pubsub:start/1.

pub fn sub(server: Server, topic: topic) -> Result(Nil, Error)

Subscribe the calling process to topic.

See avm_pubsub:sub/2.

pub fn sub_pid(
  server: Server,
  topic: topic,
  pid: process.Pid,
) -> Result(Nil, Error)

Subscribe pid to topic.

See avm_pubsub:sub/3.

pub fn unsub(server: Server, topic: topic) -> Result(Nil, Error)

Unsubscribe the calling process from topic.

See avm_pubsub:unsub/2.

pub fn unsub_pid(
  server: Server,
  topic: topic,
  pid: process.Pid,
) -> Result(Nil, Error)

Unsubscribe pid from topic.

See avm_pubsub:unsub/3.

✨ Search Document