Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d1a4af2
Start named process API
lpil Feb 12, 2025
136c250
API renovation
lpil Feb 13, 2025
bfa94e2
Changelog, remove node.to_atom
lpil Feb 13, 2025
b871e07
Name testing
lpil Feb 18, 2025
f2a1263
Update versions
lpil Feb 18, 2025
6f6f449
Node send rename
lpil Feb 19, 2025
05eb14b
New start functions
lpil Feb 19, 2025
54d4aea
Document, remove try_call functions
lpil Feb 24, 2025
542d3d3
Document and test names and calling
lpil Feb 24, 2025
b894de3
Name documentation
lpil Feb 26, 2025
8ba6625
Name tests
lpil Feb 26, 2025
57c3eae
some doc changes
bcpeinhardt Feb 26, 2025
6fa5a23
Apply suggestions from code review
lpil Feb 27, 2025
8b48031
Correct changelog
lpil Feb 27, 2025
83b9d17
Document start type
lpil Feb 27, 2025
e6206be
Update README
lpil Feb 28, 2025
607aecd
Remove selecting_record* functions
lpil Mar 4, 2025
a12986b
Remove node.untyped_send
lpil Mar 5, 2025
ca05f87
Improve monitor APIs
lpil Mar 5, 2025
8a620b6
Abnormal uses Dynamic instead of String, Use ExitReason more
sbergen Mar 5, 2025
4ffcf78
Relax abnormal exit
lpil Mar 6, 2025
5ea2e9b
Names have a programmer supplied prefix
lpil Mar 11, 2025
c54cb6e
Panic when sending fails
lpil Mar 11, 2025
d8a8761
Note replacements
lpil Mar 11, 2025
7e96509
Improve call, document
lpil Mar 13, 2025
f113865
Typos
lpil Mar 13, 2025
075cf5a
Remove unused
lpil Mar 23, 2025
963cd12
Rename selector functions
lpil Apr 23, 2025
bc5d237
Update CI
lpil Apr 23, 2025
fb37cf8
select_other
lpil Apr 23, 2025
29997fe
v1.0.0-rc1
lpil Apr 23, 2025
abd3703
Use proc_lib
lpil Apr 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
- The `selecting_process_down` function has been removed.
- The `deselecting_process_down` function has been removed.
- The `Abnormal` variant of the `ExitReason` type now holds a `Dynamic`.
- The argument ordering and labels of `call` have changed.
- In the `gleam/erlang/node` module:
- The `to_atom` function has been removed.
- The `send` function has been removed.
Expand Down
56 changes: 54 additions & 2 deletions src/gleam/erlang/process.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ pub fn deselecting(
/// but this function may be useful if you need to receive messages sent from
/// other BEAM languages that do not use the `Subject` type.
///
/// This will not select messages sent via a subject even if the message has
/// the same tag in the first position. This is because went a message is send
/// via a subject a new tag is used that is unique and specific to that subject.
///
pub fn selecting_record(
selector: Selector(payload),
tag tag: tag,
Expand Down Expand Up @@ -574,23 +578,71 @@ fn perform_call(
/// Send a message to a process and wait a given number of milliseconds for a
/// reply.
///
/// ## Panics
///
/// This function will panic under the following circumstances:
/// - The callee process exited prior to sending a reply.
/// - The callee process did not send a reply within the permitted amount of
/// time.
/// - The subject is a named subject but no process is registered with that
/// name.
///
/// ## Examples
///
/// ```gleam
/// pub type Message {
/// // This message variant is to be used with `call`.
/// // The `reply` field contains a subject that the reply message will be
/// // sent over.
/// SayHello(reply_to: Subject(String), name: String)
/// }
///
/// // Typically we make public functions that hide the details of a process'
/// // message-based API.
/// pub fn say_hello(subject: Subject(Message), name: String) -> String {
/// // The `SayHello` message constructor is given _partially applied_ with
/// // all the arguments except the reply subject, which will be supplied by
/// // the `call` function itself before sending the message.
/// process.call(subject, 100, SayHello(_, name))
/// }
///
/// // This is the message handling logic used by the process that owns the
/// // subject, and so receives the messages. In a real project it would be
/// // within a process or some higher level abstraction like an actor, but for
/// // this demonstration that has been omitted.
/// pub fn handle_message(message: Message) -> Nil {
/// case message {
/// SayHello(reply:, name:) -> {
/// let data = "Hello, " <> name <> "!"
/// // The reply subject is used to send the response back.
/// // If the receiver process does not sent a reply in time then the
/// // caller will crash.
/// process.send(reply, data)
/// }
/// }
/// }
///
/// // Here is what it looks like using the functional API to call the process.
/// pub fn run(subject: Subject(Message)) {
/// say_hello(subject, "Lucy")
/// // -> "Hello, Lucy!"
/// say_hello(subject, "Nubi")
/// // -> "Hello, Nubi!"
/// }
/// ```
///
pub fn call(
subject: Subject(message),
make_request: fn(Subject(reply)) -> message,
within timeout: Int,
waiting timeout: Int,
sending make_request: fn(Subject(reply)) -> message,
) -> reply {
perform_call(subject, make_request, select(_, timeout))
}

/// Send a message to a process and wait for a reply.
///
/// # Panics
///
/// This function will panic under the following circumstances:
/// - The callee process exited prior to sending a reply.
/// - The subject is a named subject but no process is registered with that
Expand Down
2 changes: 1 addition & 1 deletion test/gleam/erlang/process_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ pub fn call_test() {
let assert Ok(call_subject) = process.receive(parent_subject, 50)

// Call the child process and get a response.
let assert 2 = process.call(call_subject, fn(subject) { #(1, subject) }, 50)
let assert 2 = process.call(call_subject, 50, fn(subject) { #(1, subject) })
}

pub fn call_forever_test() {
Expand Down