@@ -76,10 +76,21 @@ pub fn spawn_unlinked(a: fn() -> anything) -> Pid
76
76
/// ```
77
77
///
78
78
pub opaque type Subject ( message) {
79
- Subject ( owner : Pid , tag : Reference )
79
+ Subject ( owner : Pid , tag : Dynamic )
80
80
NamedSubject ( name : Name ( message) )
81
81
}
82
82
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
+
83
94
/// A name is an identity that a process can adopt, after which they will receive
84
95
/// messages sent to that name. This has two main advantages:
85
96
///
@@ -145,7 +156,7 @@ pub fn subject_name(subject: Subject(message)) -> Result(Name(message), Nil) {
145
156
/// Create a new `Subject` owned by the current process.
146
157
///
147
158
pub fn new_subject ( ) -> Subject ( message) {
148
- Subject ( owner : self ( ) , tag : reference . new ( ) )
159
+ Subject ( owner : self ( ) , tag : reference_to_dynamic ( reference . new ( ) ) )
149
160
}
150
161
151
162
/// Get the owner process for a subject, which is the process that will
@@ -730,7 +741,7 @@ pub fn unlink(pid: Pid) -> Nil {
730
741
pub type Timer
731
742
732
743
@ 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
734
745
735
746
@ external ( erlang , "erlang" , "send_after" )
736
747
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 {
744
755
}
745
756
}
746
757
758
+ @ external ( erlang , "gleam_erlang_ffi" , "identity" )
759
+ fn reference_to_dynamic ( reference : Reference ) -> Dynamic
760
+
747
761
@ external ( erlang , "erlang" , "cancel_timer" )
748
762
fn erlang_cancel_timer ( a : Timer ) -> Dynamic
749
763
0 commit comments