[Home] Type Microsoft.FSharp.Control.MailboxProcessor


A MailboxProcessor is an asynchronous computation that includes the ability to read from a single dedicated channel, i.e. a single dedicated message queue. Anyone can send messages to a MailboxProcessor by using the Post method. A MailboxProcessor enters a state where it waits for the next message by calling its own Receive or TryReceive method. A MailboxProcessor can scan through all available messages using its own Scan or TryScan method, by using a function that selects an asynchronous computation to run based on a scan of the message queue. A MailboxProcessor generally needs to use one or more of its own Receive, TryReceive, Scan or TryScan methods. It also often typically has to allow other asynchronous computations to send messages back to the MailboxProcessor. As a result the creation functions are given a reference to the MailboxProcessor itself.

Full Type Signature

[<SealedAttribute ()>]
type MailboxProcessor<'msg> =
  class
    new : initial:(MailboxProcessor<'msg> -> Async<unit>) * ?asyncGroup:AsyncGroup ->
          MailboxProcessor<'msg>
    member
      AsyncPostAndReply : buildMessage:(AsyncReplyChannel<'reply> -> 'msg) * ?timeout:int * ?exitContext:bool ->
                          Async<'reply>
    member
      AsyncTryPostAndReply : buildMessage:(AsyncReplyChannel<'reply> -> 'msg) * ?timeout:int * ?exitContext:bool
                             -> Async<'reply option>
    member Post : message:'msg -> unit
    member
      PostAndReply : buildMessage:(AsyncReplyChannel<'reply> -> 'msg) * ?timeout:int * ?exitContext:bool -> 'reply
    member Receive : ?timeout:int -> Async<'msg>
    member Scan : scanner:('msg -> Async<'res> option) * ?timeout:int -> Async<'res>
    member Start : unit -> unit
    static member
      Start : initial:(MailboxProcessor<'msg> -> Async<unit>) * ?asyncGroup:AsyncGroup ->
              MailboxProcessor<'msg>
    member
      TryPostAndReply : buildMessage:(AsyncReplyChannel<'reply> -> 'msg) * ?timeout:int * ?exitContext:bool ->
                        'reply option
    member TryReceive : ?timeout:int -> Async<'msg option>
    member TryScan : scanner:('msg -> Async<'res> option) * ?timeout:int -> Async<'res option>
    member DefaultTimeout : int
    member UnsafeMessageQueueContents : seq<'msg>
    member DefaultTimeout : int with set
  end

Instance Members

MemberDescription
member
  AsyncPostAndReply : buildMessage:(AsyncReplyChannel<'reply> -> 'msg) *
                      ?timeout:int * ?exitContext:bool -> Async<'reply>
Post a message to the message queue of the MailboxProcessor and await a reply on the channel asynchronously. The message is produced by a single call to the first function which must build a message containing the reply channel. The receiving MailboxProcessor must process this message and invoke the Reply method on the reply channel precisly once.
member
  AsyncTryPostAndReply : buildMessage:(AsyncReplyChannel<'reply> -> 'msg) *
                         ?timeout:int * ?exitContext:bool ->
                         Async<'reply option>
Like PostAndReplyAsync, but return None if no reply within the timeout period.
member DefaultTimeout : int
Raise a timeout exception if a message not received in this amount of time. Default infinite.
member DefaultTimeout : int with set
Raise a timeout exception if a message not received in this amount of time. Default infinite.
member Post : message:'msg -> unit
Post a message to the message queue of the MailboxProcessor, asynchronously
member
  PostAndReply : buildMessage:(AsyncReplyChannel<'reply> -> 'msg) *
                 ?timeout:int * ?exitContext:bool -> 'reply
Post a message to the message queue of the MailboxProcessor and await a reply on the channel. The message is produced by a single call to the first function which must build a message containing the reply channel. The receiving MailboxProcessor must process this message and invoke the Reply method on the reply channel precisly once.
member Receive : ?timeout:int -> Async<'msg>
Return an asynchronous computation which will consume the first message in arrival order. No thread is blocked while waiting for further messages. Raise a TimeoutException if the timeout is exceeded.
member
  Scan : scanner:('msg -> Async<'res> option) * ?timeout:int ->
         Async<'res>
Return an asynchronous computation which will look through messages in arrival order until 'scanner' returns a Some value. No thread is blocked while waiting for further messages. Raise a TimeoutException if the timeout is exceeded.
member Start : unit -> unit
Start the MailboxProcessor
member
  TryPostAndReply : buildMessage:(AsyncReplyChannel<'reply> -> 'msg) *
                    ?timeout:int * ?exitContext:bool -> 'reply option
Like PostAndReply, but return None if no reply within the timeout period.
member TryReceive : ?timeout:int -> Async<'msg option>
Return an asynchronous computation which will consume the first message in arrival order. No thread is blocked while waiting for further messages. Return None if the timeout is exceeded.
member
  TryScan : scanner:('msg -> Async<'res> option) * ?timeout:int ->
            Async<'res option>
Return an asynchronous computation which will look through messages in arrival order until 'scanner' returns a Some value. No thread is blocked while waiting for further messages. Return None if the timeout is exceeded.
member UnsafeMessageQueueContents : seq<'msg>

Static Members

MemberDescription
new : initial:(MailboxProcessor<'msg> -> Async<unit>) *
      ?asyncGroup:AsyncGroup -> MailboxProcessor<'msg>
Create an instance of a MailboxProcessor. The asynchronous computation executed by the processor is the one returned by the 'initial' function. This function is not executed until 'Start' is called.
member
  Start : initial:(MailboxProcessor<'msg> -> Async<unit>) *
          ?asyncGroup:AsyncGroup -> MailboxProcessor<'msg>
Create and start an instance of a MailboxProcessor. The asynchronous computation executed by the processor is the one returned by the 'initial' function.

See Also

Microsoft.FSharp.Control


Documentation for assembly FSharp.Core, version 1.9.6.0, generated using F# Programming Language version 1.9.6.0