mailboxprocessor

Use Post or PostAndAsyncReply with F#'s MailboxProcessor?

微笑、不失礼 提交于 2019-12-22 05:53:23
问题 I've seen different snippets demonstrating a Put message that returns unit with F#'s MailboxProcessor . In some, only the Post method is used while others use PostAndAsyncReply , with the reply channel immediately replying once the message is being processed. In doing some testing, I found a significant time lag when awaiting the reply, so it seems that unless you need a real reply, you should use Post . Note: I started asking this in another thread but thought it useful to post as a full

Async.TryCancelled doesn't work with Async.RunSynchronously

懵懂的女人 提交于 2019-12-21 06:45:15
问题 I try to create an agent that updates UI based on user interaction. If user clicks on a button, the GUI should be refreshed. The preparation of model takes a long time, so it is desirable that if user clicks on other button, the preparation is cancelled and the new one is started. What I have so far: open System.Threading type private RefreshMsg = | RefreshMsg of AsyncReplyChannel<CancellationTokenSource> type RefresherAgent() = let mutable cancel : CancellationTokenSource = null let

Proper way how to prepare data in async cancellable workflow with responsive UI

耗尽温柔 提交于 2019-12-11 14:40:41
问题 This question is based on Async.TryCancelled doesn't work with Async.RunSynchronously that looks complex, so I will cut a simple part that I try to solve. Suppose I have this functions: let prepareModel () = async { // this might take a lot of time (1-50seconds) let! a = ... let! b = ... let! res = combine a b return res } let updateUI model = runOnUIThread model prepareModel prepares data that should be displayed to the user. updateUI refreshes the UI (removes old controls and creates new

How to use TryScan in F# properly

◇◆丶佛笑我妖孽 提交于 2019-12-10 14:56:32
问题 I was trying to find an example about how to use TryScan , but haven't found any, could you help me? What I would like to do (quite simplified example): I have a MailboxProcessor that accepts two types of mesages. First one GetState returns current state. GetState messages are sent quite frequently The other UpdateState is very expensive (time consuming) - e.g. downloading something from internet and then updates the state accordingly. UpdateState is called only rarely. My problem is -

A MailboxProcessor that operates with a LIFO logic

女生的网名这么多〃 提交于 2019-12-06 04:01:11
问题 I am learning about F# agents ( MailboxProcessor ). I am dealing with a rather unconventional problem. I have one agent ( dataSource ) which is a source of streaming data. The data has to be processed by an array of agents ( dataProcessor ). We can consider dataProcessor as some sort of tracking device. Data may flow in faster than the speed with which the dataProcessor may be able to process its input. It is OK to have some delay. However, I have to ensure that the agent stays on top of its

F# MailboxProcessor questions

隐身守侯 提交于 2019-12-03 15:18:08
问题 I've created a console program using the code from http://fssnip.net/3K. And I found that I'd to add "System.Console.ReadLine() |> ignore" at the end to wait for the finish of threads. Is it possible to tell all the MailBoxProcessors are done and the program can exit itself? I tried to change the test url "www.google.com" to something invalid url and I got the following output. Is it possible to avoid the "outputting race"? http://www.google.co1m crawled by agent 1. AgAAAent gent 3 is done.

F# MailboxProcessor questions

江枫思渺然 提交于 2019-12-03 03:56:53
I've created a console program using the code from http://fssnip.net/3K . And I found that I'd to add "System.Console.ReadLine() |> ignore" at the end to wait for the finish of threads. Is it possible to tell all the MailBoxProcessors are done and the program can exit itself? I tried to change the test url "www.google.com" to something invalid url and I got the following output. Is it possible to avoid the "outputting race"? http://www.google.co1m crawled by agent 1. AgAAAent gent 3 is done. gent 2 is done. 5 is done. gent 4 is done. Agent USupervisor RL collector is done. is done. 1 is done.

MailboxProcessor and exceptions

亡梦爱人 提交于 2019-11-30 14:41:57
问题 I wonder, why MailboxProcessor 's default strategy of handling exceptions is just silently ignore them. For example: let counter = MailboxProcessor.Start(fun inbox -> let rec loop() = async { printfn "waiting for data..." let! data = inbox.Receive() failwith "fail" // simulate throwing of an exception printfn "Got: %d" data return! loop() } loop ()) () counter.Post(42) counter.Post(43) counter.Post(44) Async.Sleep 1000 |> Async.RunSynchronously and nothing happens. There is no fatal stop of