Hive.Group
hive · API reference
Local process groups.
Local process groups: a named set of members, no uniqueness.
The local analog of :pg — many members per name, used to fan a message out to all of them. Same Type.Id-witnessed typing as Registry; same kcas backing.
type tA local group table.
type 'a keyA typed group name. Members of this group have type 'a.
type membershipReturned by join; the only way to leave.
val create : unit -> tCreate an empty group table.
ocaml]
let groups = Hive.Group.create ()val key : string -> 'a keyFresh key for a group name; share the key to share the group.
Two calls with the same string create incompatible keys. Define the key once next to the worker or capability it names, then reuse that value.
val name : _ key -> stringThe textual group name carried by a key.
val join : t -> 'a key -> 'a -> (membership, [ `Name_in_use ]) resultAdd a member. Error Name_in_use` when the name is already a group under a different key.
ocaml]
let key = Hive.Group.key "chat:room-1" in
let token = Result.get_ok (Hive.Group.join groups key client_addr)val leave : t -> membership -> unitRemove the member added by this membership. Idempotent.
val members : t -> 'a key -> 'a listCurrent members, newest first. Empty when the name is free or owned by a different key.
ocaml]
List.iter (fun addr -> ignore (Hive.Addr.send addr (`Text "hello")))
(Hive.Group.members groups key)