Skip to content

Commit

Permalink
Better docs
Browse files Browse the repository at this point in the history
  • Loading branch information
chouzar committed May 6, 2024
1 parent 247db90 commit e5fbc57
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/chip/)


////Chip is a gleam process registry that plays along the [Gleam Erlang](https://hexdocs.pm/gleam_erlang/) `Subject` type.
////
////It lets tag subjects under a name or group to later reference them. Will also automatically delist dead processes.
Chip is a gleam process registry that plays along the [Gleam Erlang](https://hexdocs.pm/gleam_erlang/) `Subject` type.

It lets tag subjects under a name or group to later reference them. Will also automatically delist dead processes.

### Example

Expand Down
2 changes: 1 addition & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "chip"
version = "0.5.0"
version = "0.5.1"
description = "A Gleam registry library"
licences = ["Apache-2.0"]

Expand Down
24 changes: 12 additions & 12 deletions src/chip.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,24 @@ type Registry(name, group, message) =

/// This is the message type used internally by Chip.
///
/// Its generics `name`, `group`, and `msg` correspond to whatever types we do want to assign to the
/// registry when initializing. A Chip instance only accepts `Subject's of the same type so it is
/// sometimes useful to state the types on startup. For example:
/// `Message(name, group, msg)` generics correspond to the types that the registry will use to manage
/// unique names, group names and Subject messages. When building your system it is useful to state
/// these on startup. For example:
///
/// ```gleam
/// type Group {
/// GroupA
/// GroupB
/// GroupC
/// A
/// B
/// C
/// }
///
/// > let assert Ok(registry) = chip.start()
/// > let registry: process.Subject(chip.Message(String, Group, Chat))
/// let assert Ok(registry) = chip.start()
/// let registry: process.Subject(chip.Message(String, Group, Chat))
/// ```
///
/// By specifying the types we can document the kind of registry we are working with. For example the
/// registry above lets us tag subjects that use the `Subject(Chat)` type; it lets us tag individual
/// subjects through stringified names; finally lets us group subjects into a group A, B or C.
///
/// Of course we can always rely on gleam's type inference to do the typing for us.
/// subjects through stringified names; finally lets us group subjects into a groups A, B or C.
pub opaque type Message(name, group, msg) {
NamedSubject(client: Subject(Result(Subject(msg), Nil)), name: name)
NamedRegistrant(subject: Subject(msg), name: name)
Expand Down Expand Up @@ -135,7 +133,7 @@ pub fn group(
///
/// ```gleam
/// > chip.find(registry, "group-a")
/// [subject]
/// [subject_1, subject_2, subject_3]
/// ```
pub fn members(registry, group) -> List(Subject(msg)) {
process.call(registry, GroupedSubjects(_, group), 10)
Expand All @@ -149,6 +147,8 @@ pub fn members(registry, group) -> List(Subject(msg)) {
/// > chip.broadcast(registry, "group-a", fn(subject) {
/// > process.send(subject, Message(data))
/// > })
/// Nil
/// ```
pub fn broadcast(
registry: Subject(Message(name, group, message)),
group: group,
Expand Down

0 comments on commit e5fbc57

Please sign in to comment.