-
-
Save jasondown/a769d0cf50c229e1d5e6d01f9f60386b to your computer and use it in GitHub Desktop.
Simple output message agent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type OutputMessage = | |
| Print of string | |
let agent output = MailboxProcessor<OutputMessage>.Start(fun inbox -> | |
let rec loop () = async { | |
let! message = inbox.Receive() | |
match message with | |
| Print msg -> | |
output msg | |
return! loop() } | |
loop() ) | |
//test | |
let consoleAgent = agent System.Console.Out.WriteLine | |
consoleAgent.Post(Print "hello agent") | |
consoleAgent.Post(Print "hello again") | |
// fsi: | |
// hello agent | |
// val it : unit = () | |
// hello again | |
// val it : unit = () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment