[Home] Type Microsoft.FSharp.Control.Mailboxes.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

[<ExperimentalAttribute ("This type is part of an experimental feature called 'asynchronous workflows'")>]
type MailboxProcessor<'msg> =
  class
  end
  with
    interface IChannel<'msg>
    new : initial:(MailboxProcessor<'msg> -> Async<unit>) * ?asyncGroup:AsyncGroup -> MailboxProcessor<'msg>
    [<Obsolete
      ("This member has been replaced by an object constructor. Use 'new MailboxProcessor<_>(...)' instead of 'MailboxProcessor<_>.Create(...)'")>]
    static member
      Create : initial:(MailboxProcessor<'msg> -> Async<unit>) * ?asyncGroup:AsyncGroup -> MailboxProcessor<'msg>
    member Post : 'msg -> unit
    member PostAndReply : (AsyncReplyChannel<'reply> -> 'msg) * ?timeout:int * ?exitContext:bool -> 'reply
    member PostAndReplyAsync : (AsyncReplyChannel<'reply> -> 'msg) * ?timeout:int * ?exitContext:bool -> Async<'reply>
    [<Obsolete ("This member has been renamed 'PostAndReply'")>]
    member PostSync : (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 : (AsyncReplyChannel<'reply> -> 'msg) * ?timeout:int * ?exitContext:bool -> 'reply option
    member
      TryPostAndReplyAsync : (AsyncReplyChannel<'reply> -> 'msg) * ?timeout:int * ?exitContext:bool ->
                             Async<'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 DefaultTimeout : int
member DefaultTimeout : int with set
member Post : 'msg -> unit
Post a message to the message queue of the MailboxProcessor, asynchronously
member
  PostAndReply : (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
member
  PostAndReplyAsync : (AsyncReplyChannel<'reply> -> 'msg) * ?timeout:int *
                      ?exitContext:bool -> Async<'reply>
Post a message to the message queue of the MailboxProcessor and await an eventual reply on the channel. Return None if timeout exceeded.
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 : (AsyncReplyChannel<'reply> -> 'msg) * ?timeout:int *
                    ?exitContext:bool -> 'reply option
Post a message to the message queue of the MailboxProcessor and await a reply on the channel
member
  TryPostAndReplyAsync : (AsyncReplyChannel<'reply> -> 'msg) * ?timeout:int *
                         ?exitContext:bool -> Async<'reply option>
Post a message to the message queue of the MailboxProcessor and eventually await a reply on the channel. Return None if timeout exceeded.
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.

Deprecated Members

MemberDescription
[<Obsolete
  ("This member has been replaced by an object constructor. Use 'new MailboxProcessor<_>(...)' instead of 'MailboxProcessor<_>.Create(...)'")>]
member
  Create : initial:(MailboxProcessor<'msg> -> Async<unit>) *
           ?asyncGroup:AsyncGroup -> MailboxProcessor<'msg>

Note: This member has been replaced by an object constructor. Use 'new MailboxProcessor<_>(...)' instead of 'MailboxProcessor<_>.Create(...)'

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.
[<Obsolete ("This member has been renamed 'PostAndReply'")>]
member
  PostSync : (AsyncReplyChannel<'reply> -> 'msg) * ?timeout:int *
             ?exitContext:bool -> 'reply

Note: This member has been renamed 'PostAndReply'

See Also

Microsoft.FSharp.Control.Mailboxes


Documentation for assembly FSharp.Core, version 1.9.4.19, generated using F# version 1.9.4.19