Skip to content

Commit 51b0d45

Browse files
committed
v1.3.0
1 parent b1e94ae commit 51b0d45

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v1.3.0 - 2025-08-03
4+
5+
- Internal changes to the subject type.
6+
37
## v1.2.0 - 2025-07-02
48

59
- The `gleam/erlang/process` module gains the `subject_name` function.

gleam.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "gleam_erlang"
22

3-
version = "1.2.0"
3+
version = "1.3.0"
44
licences = ["Apache-2.0"]
55
description = "Types and functions for programs running on Erlang!"
66

src/gleam/erlang/process.gleam

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,21 @@ pub fn spawn_unlinked(a: fn() -> anything) -> Pid
7676
/// ```
7777
///
7878
pub opaque type Subject(message) {
79-
Subject(owner: Pid, tag: Reference)
79+
Subject(owner: Pid, tag: Dynamic)
8080
NamedSubject(name: Name(message))
8181
}
8282

83+
/// Create a subject for the given process with the give tag. This is unsafe!
84+
/// There's nothing here that verifies that the message the subject receives is
85+
/// expected and that the tag is not already in use.
86+
///
87+
/// You should almost certainly not use this function.
88+
///
89+
@internal
90+
pub fn unsafely_create_subject(owner: Pid, tag: Dynamic) -> Subject(message) {
91+
Subject(owner, tag)
92+
}
93+
8394
/// A name is an identity that a process can adopt, after which they will receive
8495
/// messages sent to that name. This has two main advantages:
8596
///
@@ -145,7 +156,7 @@ pub fn subject_name(subject: Subject(message)) -> Result(Name(message), Nil) {
145156
/// Create a new `Subject` owned by the current process.
146157
///
147158
pub fn new_subject() -> Subject(message) {
148-
Subject(owner: self(), tag: reference.new())
159+
Subject(owner: self(), tag: reference_to_dynamic(reference.new()))
149160
}
150161

151162
/// Get the owner process for a subject, which is the process that will
@@ -730,7 +741,7 @@ pub fn unlink(pid: Pid) -> Nil {
730741
pub type Timer
731742

732743
@external(erlang, "erlang", "send_after")
733-
fn pid_send_after(a: Int, b: Pid, c: #(Reference, msg)) -> Timer
744+
fn pid_send_after(a: Int, b: Pid, c: #(Dynamic, msg)) -> Timer
734745

735746
@external(erlang, "erlang", "send_after")
736747
fn name_send_after(a: Int, b: Name(msg), c: #(Name(msg), msg)) -> Timer
@@ -744,6 +755,9 @@ pub fn send_after(subject: Subject(msg), delay: Int, message: msg) -> Timer {
744755
}
745756
}
746757

758+
@external(erlang, "gleam_erlang_ffi", "identity")
759+
fn reference_to_dynamic(reference: Reference) -> Dynamic
760+
747761
@external(erlang, "erlang", "cancel_timer")
748762
fn erlang_cancel_timer(a: Timer) -> Dynamic
749763

0 commit comments

Comments
 (0)