@@ -379,6 +379,10 @@ pub fn deselecting(
379379/// but this function may be useful if you need to receive messages sent from
380380/// other BEAM languages that do not use the `Subject` type.
381381///
382+ /// This will not select messages sent via a subject even if the message has
383+ /// the same tag in the first position. This is because went a message is send
384+ /// via a subject a new tag is used that is unique and specific to that subject.
385+ ///
382386pub fn selecting_record (
383387 selector : Selector ( payload) ,
384388 tag tag : tag,
@@ -574,23 +578,71 @@ fn perform_call(
574578/// Send a message to a process and wait a given number of milliseconds for a
575579/// reply.
576580///
581+ /// ## Panics
582+ ///
577583/// This function will panic under the following circumstances:
578584/// - The callee process exited prior to sending a reply.
579585/// - The callee process did not send a reply within the permitted amount of
580586/// time.
581587/// - The subject is a named subject but no process is registered with that
582588/// name.
583589///
590+ /// ## Examples
591+ ///
592+ /// ```gleam
593+ /// pub type Message {
594+ /// // This message variant is to be used with `call`.
595+ /// // The `reply` field contains a subject that the reply message will be
596+ /// // sent over.
597+ /// SayHello(reply_to: Subject(String), name: String)
598+ /// }
599+ ///
600+ /// // Typically we make public functions that hide the details of a process'
601+ /// // message-based API.
602+ /// pub fn say_hello(subject: Subject(Message), name: String) -> String {
603+ /// // The `SayHello` message constructor is given _partially applied_ with
604+ /// // all the arguments except the reply subject, which will be supplied by
605+ /// // the `call` function itself before sending the message.
606+ /// process.call(subject, 100, SayHello(_, name))
607+ /// }
608+ ///
609+ /// // This is the message handling logic used by the process that owns the
610+ /// // subject, and so receives the messages. In a real project it would be
611+ /// // within a process or some higher level abstraction like an actor, but for
612+ /// // this demonstration that has been omitted.
613+ /// pub fn handle_message(message: Message) -> Nil {
614+ /// case message {
615+ /// SayHello(reply:, name:) -> {
616+ /// let data = "Hello, " <> name <> "!"
617+ /// // The reply subject is used to send the response back.
618+ /// // If the receiver process does not sent a reply in time then the
619+ /// // caller will crash.
620+ /// process.send(reply, data)
621+ /// }
622+ /// }
623+ /// }
624+ ///
625+ /// // Here is what it looks like using the functional API to call the process.
626+ /// pub fn run(subject: Subject(Message)) {
627+ /// say_hello(subject, "Lucy")
628+ /// // -> "Hello, Lucy!"
629+ /// say_hello(subject, "Nubi")
630+ /// // -> "Hello, Nubi!"
631+ /// }
632+ /// ```
633+ ///
584634pub fn call (
585635 subject : Subject ( message) ,
586- make_request : fn ( Subject ( reply ) ) -> message ,
587- within timeout : Int ,
636+ waiting timeout : Int ,
637+ sending make_request : fn ( Subject ( reply ) ) -> message ,
588638) -> reply {
589639 perform_call ( subject , make_request , select ( _, timeout ) )
590640}
591641
592642/// Send a message to a process and wait for a reply.
593643///
644+ /// # Panics
645+ ///
594646/// This function will panic under the following circumstances:
595647/// - The callee process exited prior to sending a reply.
596648/// - The subject is a named subject but no process is registered with that
0 commit comments