From 010ed251ad38b50f39f00d38c6705c84ddecf820 Mon Sep 17 00:00:00 2001 From: Gauthier Segay Date: Thu, 30 Jun 2016 15:35:58 +0200 Subject: [PATCH] MailboxProcessor * Indentation of signature * sample output as code blocks --- ...l.mailboxprocessor['msg]-class-[fsharp].md | 110 ++++++++++-------- 1 file changed, 60 insertions(+), 50 deletions(-) diff --git a/docs/conceptual/control.mailboxprocessor['msg]-class-[fsharp].md b/docs/conceptual/control.mailboxprocessor['msg]-class-[fsharp].md index 78f7e09c..c7f0ef02 100644 --- a/docs/conceptual/control.mailboxprocessor['msg]-class-[fsharp].md +++ b/docs/conceptual/control.mailboxprocessor['msg]-class-[fsharp].md @@ -26,25 +26,25 @@ A message-processing agent which executes an asynchronous computation. [] [] type MailboxProcessor<'Msg> = -class -interface IDisposable -new MailboxProcessor : (MailboxProcessor<'Msg> -> Async) * ?CancellationToken -> MailboxProcessor<'Msg> -member this.Post : 'Msg -> unit -member this.PostAndAsyncReply : (AsyncReplyChannel<'Reply> -> 'Msg) * int option -> Async<'Reply> -member this.PostAndReply : (AsyncReplyChannel<'Reply> -> 'Msg) * int option -> 'Reply -member this.PostAndTryAsyncReply : (AsyncReplyChannel<'Reply> -> 'Msg) * ?int -> Async<'Reply option> -member this.Receive : ?int -> Async<'Msg> -member this.Scan : ('Msg -> Async<'T> option) * ?int -> Async<'T> -member this.Start : unit -> unit -static member Start : (MailboxProcessor<'Msg> -> Async) * ?CancellationToken -> MailboxProcessor<'Msg> -member this.TryPostAndReply : (AsyncReplyChannel<'Reply> -> 'Msg) * ?int -> 'Reply option -member this.TryReceive : ?int -> Async<'Msg option> -member this.TryScan : ('Msg -> Async<'T> option) * ?int -> Async<'T option> -member this.add_Error : Handler -> unit -member this.CurrentQueueLength : int -member this.DefaultTimeout : int with get, set -member this.Error : IEvent -member this.remove_Error : Handler -> unit + class + interface IDisposable + new MailboxProcessor : (MailboxProcessor<'Msg> -> Async) * ?CancellationToken -> MailboxProcessor<'Msg> + member this.Post : 'Msg -> unit + member this.PostAndAsyncReply : (AsyncReplyChannel<'Reply> -> 'Msg) * int option -> Async<'Reply> + member this.PostAndReply : (AsyncReplyChannel<'Reply> -> 'Msg) * int option -> 'Reply + member this.PostAndTryAsyncReply : (AsyncReplyChannel<'Reply> -> 'Msg) * ?int -> Async<'Reply option> + member this.Receive : ?int -> Async<'Msg> + member this.Scan : ('Msg -> Async<'T> option) * ?int -> Async<'T> + member this.Start : unit -> unit + static member Start : (MailboxProcessor<'Msg> -> Async) * ?CancellationToken -> MailboxProcessor<'Msg> + member this.TryPostAndReply : (AsyncReplyChannel<'Reply> -> 'Msg) * ?int -> 'Reply option + member this.TryReceive : ?int -> Async<'Msg option> + member this.TryScan : ('Msg -> Async<'T> option) * ?int -> Async<'T option> + member this.add_Error : Handler -> unit + member this.CurrentQueueLength : int + member this.DefaultTimeout : int with get, set + member this.Error : IEvent + member this.remove_Error : Handler -> unit end ``` @@ -90,40 +90,50 @@ This type is named **FSharpMailboxProcessor** in the .NET assembly. If accessing |[Start](https://msdn.microsoft.com/library/ebf18bf3-ba17-42b9-91ac-313a7eee6fa0)|Creates and starts an agent. The **body** function is used to generate the asynchronous computation executed by the agent.| **The following example shows the basic use of the MailboxProcessor class.** [!code-fsharp[Main](snippets/fsmailboxprocessor/snippet2.fs)] + **Sample Output** -**Press any key...** -**Message count = 0. Waiting for next message.** -**Message received. ID: 1 Contents: ABC** -**Message count = 1. Waiting for next message.** -**Message received. ID: 2 Contents: XYZ** -**Message count = 2. Waiting for next message.****The following example shows how to use MailboxProcessor to create a simple agent that accepts various types of messages and returns appropriate replies. This server agent represents a market maker, which is a buying and selling agent on a stock exchange that sets bid and ask prices for assets. Clients can query for prices, or buy and sell shares.** + +```text +Press any key... +Message count = 0. Waiting for next message. +Message received. ID: 1 Contents: ABC +Message count = 1. Waiting for next message. +Message received. ID: 2 Contents: XYZ +Message count = 2. Waiting for next message. +``` + +The following example shows how to use MailboxProcessor to create a simple agent that accepts various types of messages and returns appropriate replies. This server agent represents a market maker, which is a buying and selling agent on a stock exchange that sets bid and ask prices for assets. Clients can query for prices, or buy and sell shares.** [!code-fsharp[Main](snippets/fsmailboxprocessor/snippet3.fs)] **Sample Output** -**Posting message for AAA** -**Replying with Info for AAA** -**Posting message for BBB** -**Replying with Notification:** -**Bought 100 units of BBB at price $20.100000. Total purchase $2010.000000.** -**Marketmaker balance: $ 2010.00** -**Posting message for CCC** -**Replying with Notification:** -**Sold 100 units of CCC at price $30.000000. Total sale $3000.000000.** -**Marketmaker balance: $ -990.00** -**Posting message for WrongCode** -**Posting message with large number of shares of AAA.** -**Insufficient shares to fulfill order for 1000000000 units of AAA.** -**Posting message with too large a monetary amount.** -**Insufficient cash to fulfill order for 100000000 units of AAA.** -**Press any key...** -**Posting BUY CCC 1338.** -**Replying with Notification:** -**Bought 1338 units of CCC at price $30.150000. Total purchase $40340.700000.** -**Marketmaker balance: $ 39350.70** -**Program+Snippet3+Reply+Notify** -**Posting BUY BBB 1961.** -**Replying with Notification:** -**Bought 1961 units of BBB at price $20.100000. Total purchase $39416.100000.** -**Marketmaker balance: $ 78766.80** + +```text +Posting message for AAA +Replying with Info for AAA +Posting message for BBB +Replying with Notification: +Bought 100 units of BBB at price $20.100000. Total purchase $2010.000000. +Marketmaker balance: $ 2010.00 +Posting message for CCC +Replying with Notification: +Sold 100 units of CCC at price $30.000000. Total sale $3000.000000. +Marketmaker balance: $ -990.00 +Posting message for WrongCode +Posting message with large number of shares of AAA. +Insufficient shares to fulfill order for 1000000000 units of AAA. +Posting message with too large a monetary amount. +Insufficient cash to fulfill order for 100000000 units of AAA. +Press any key... +Posting BUY CCC 1338. +Replying with Notification: +Bought 1338 units of CCC at price $30.150000. Total purchase $40340.700000. +Marketmaker balance: $ 39350.70 +Program+Snippet3+Reply+Notify +Posting BUY BBB 1961. +Replying with Notification: +Bought 1961 units of BBB at price $20.100000. Total purchase $39416.100000. +Marketmaker balance: $ 78766.80 +``` + ## Platforms Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2