chip

A pure gleam process registry that plays along types and gleam OTP abstractions. Will automatically delist dead processes.

Example

import gleam/erlang/process
import chip

// Names can be built out of any primitive or even types.
type Name {
  A
  B
}

// We can start the registry and register a new subject 
let assert Ok(registry) = chip.start()
chip.register(registry, A, process.new_subject())

// If we lose scope of our processes, just look it up in the registry!
let assert Ok(subject) = chip.find(registry, A)
let assert Error(chip.NotFound) = chip.find(registry, B)

Types

pub type Errors {
  NotFound
}

Constructors

  • NotFound

These are the possible messages that our registry can handle, this is an opaque type so you would use these commands through the equivalent functions.

pub opaque type Message(name, message)

Functions

pub fn find(registry: Subject(Message(a, b)), name: a) -> Result(
  Subject(b),
  Errors,
)

Looks up a subject through its given name.

Example

> chip.find(reigstry, "MyProcess") 
Ok(subject)
pub fn register(registry: Subject(Message(a, b)), name: a, subject: Subject(
    b,
  )) -> Nil

Manually registers a Subject within the registry.

Example

> chip.register(registry, "MyProcess", process.new_subject())
Nil
pub fn start() -> Result(Subject(Message(a, b)), StartError)

Starts our registry.

Example

> chip.start()
Ok(registry)
pub fn unregister(registry: Subject(Message(a, b)), name: a) -> Nil

Manually unregister a Subject within the registry.

Example

> chip.unregister(registry, "MyProcess")
Nil
Search Document