@@ -76,10 +76,21 @@ pub fn spawn_unlinked(a: fn() -> anything) -> Pid
7676/// ```
7777///
7878pub 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///
147158pub 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 {
730741pub 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" )
736747fn 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" )
748762fn erlang_cancel_timer ( a : Timer ) -> Dynamic
749763
0 commit comments