Skip to content

Commit 63e5b5c

Browse files
committed
Process registration documentation
1 parent 824a3da commit 63e5b5c

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/gleam/erlang/process.gleam

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -715,17 +715,30 @@ pub fn send_abnormal_exit(pid: Pid, reason: String) -> Nil {
715715
@external(erlang, "gleam_erlang_ffi", "trap_exits")
716716
pub fn trap_exits(a: Bool) -> Nil
717717

718-
// TODO: test
719-
// TODO: document
718+
/// Register a process under a given name, allowing it to be looked up using
719+
/// the `named` function.
720+
///
721+
/// This function will return an error under the following conditions:
722+
/// - The process for the pid no longer exists.
723+
/// - The name has already been registered.
724+
/// - The process already has a name.
725+
/// - The name is the atom `undefined`, which is reserved by Erlang.
726+
///
720727
@external(erlang, "gleam_erlang_ffi", "register_process")
721728
pub fn register(pid: Pid, name: Atom) -> Result(Nil, Nil)
722729

723-
// TODO: test
724-
// TODO: document
730+
/// Un-register a process name, after which the process can no longer be looked
731+
/// up by that name, and both the name and the process can be re-used in other
732+
/// registrations.
733+
///
734+
/// It is possible to un-register process that are not from your application,
735+
/// including those from Erlang/OTP itself. This is not recommended and will
736+
/// likely result in undesirable behaviour and crashes.
737+
///
725738
@external(erlang, "gleam_erlang_ffi", "unregister_process")
726739
pub fn unregister(name: Atom) -> Result(Nil, Nil)
727740

728-
// TODO: test
729-
// TODO: document
741+
/// Look up a process by name, returning the pid if it exists.
742+
///
730743
@external(erlang, "gleam_erlang_ffi", "process_named")
731744
pub fn named(name: Atom) -> Result(Pid, Nil)

0 commit comments

Comments
 (0)