chip

Chip is a gleam process registry that plays along gleam erlang/OTP Subject type.

It lets us group subjects of the same type so that we can later reference them all as a group, or sub-group if we decide to name them. Will also automatically delist dead processes.

Types

pub opaque type Action(name, message)

Functions

pub fn all(registry: Subject(Action(a, b))) -> List(Subject(b))

Returns all registered Subjects.

Example

> chip.all(registry) 
[subject_a, subject_b, subject_c]
pub fn deregister(
  registry: Subject(Action(a, b)),
  name: a,
) -> Nil

Manually deregister a named group of Subjects.

Example

> chip.deregister(registry, "MySubjects")
Nil
pub fn lookup(
  registry: Subject(Action(a, b)),
  name: a,
) -> List(Subject(b))

Looks up named subgroup of Subjects.

Example

> chip.lookup(registry, "MySubjects") 
[subject_a, subject_c]
pub fn register(
  registry: Subject(Action(a, b)),
  start: fn() -> Result(Subject(b), StartError),
) -> Result(Subject(b), StartError)

Manually registers a Subject.

Example

> chip.register(registry, fn() { start_my_subject() })
Ok(registered_subject)
pub fn register_as(
  registry: Subject(Action(a, b)),
  name: a,
  start: fn() -> Result(Subject(b), StartError),
) -> Result(Subject(b), StartError)

Manually registers a Subject under a named group.

Example

> chip.register(registry, "MySubjects", fn() { start_my_subject() })
Ok(registered_subject)
pub fn start() -> Result(Subject(Action(a, b)), StartError)

Starts the registry.

Example

> chip.start()
Ok(registry)
pub fn stop(registry: Subject(Action(a, b))) -> ExitReason

Stops the registry, all grouped Subjects will be gone.

Example

> chip.stop(registry)
Normal
Search Document