Questions tagged [mailboxprocessor]

F#'s MailboxProcessor class is essentially a dedicated message queue running on its own thread. Any thread can send the MailboxProcessor a message asynchronously or synchronously, allowing threads to communicate between one another through message passing. This style of message-passing concurrency is inspired by the Erlang programming language.

F#'s MailboxProcessor class is essentially a dedicated message queue running on its own thread. Any thread can send the MailboxProcessor a message asynchronously or synchronously, allowing threads to communicate between one another through message passing. This style of message-passing concurrency is inspired by the Erlang programming language.

For getting started with MailboxProcessor, please visit:

72 questions
26
votes
2 answers

memory leaks in Microsoft.FSharp.Control.Mailbox?

I'm hunting for some memory-leaks in a long runing service (using F#) right now. The only "strange" thing I've seen so far is the following: I use a MailboxProcessor in a subsystem with an algebraic-datatype named QueueChannelCommands (more or less…
Random Dev
  • 51,810
  • 9
  • 92
  • 119
18
votes
2 answers

MailboxProcessor and exceptions

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..." …
qehgt
  • 2,972
  • 1
  • 22
  • 36
13
votes
2 answers

MailboxProcessor from C#

Have you tried to use a MailboxProcessor of T from C#? Could you post sample code? How do you start a new one, post messages to it, and how do you process them?
GregC
  • 7,737
  • 2
  • 53
  • 67
12
votes
1 answer

MailboxProcessor.PostAndReply design choice

Looking at: member this.PostAndReply : (AsyncReplyChannel<'Reply> -> 'Msg) * ?int -> 'Reply I can't figure out why the signature looks so counter-intuitive to me. What we want to do is posting a message to an agent, and wait for a reply. Why do we…
Okay
  • 224
  • 1
  • 9
11
votes
1 answer

Passing messages between remote MailboxProcessors?

I'm using MailboxProcessor classes in order to keep separate agents that do their own thing. Normally agents can communicate with one another in the same process, but I want agents to talk to one another when they are on separate processes or even…
Dmitri Nesteruk
  • 23,067
  • 22
  • 97
  • 166
10
votes
1 answer

Why would disposal of resources be delayed when using the "use" binding within an async computation expression?

I've got an agent which I set up to do some database work in the background. The implementation looks something like this: let myAgent = MailboxProcessor.Start(fun inbox -> let rec loop = async { let! data =…
ckramer
  • 9,419
  • 1
  • 24
  • 38
9
votes
1 answer

Unit testing an agent

I am trying to test a MailboxProcessor in F#. I want to test that the function f I am giving is actually executed when posting a message. The original code is using Xunit, but I made an fsx of it that I can execute using fsharpi. So far I am doing…
Yoann
  • 546
  • 4
  • 11
8
votes
1 answer

F# MailboxProcessor and Functional Design

If state is regarded as a bad idea for functions why is it regarded as okay have a state when you use a MailboxProcessor? To expand, I was explaining functional programming to someone, how functions don't use state (no variables outside the…
Fsharp Pete
  • 741
  • 4
  • 16
7
votes
1 answer

Canceled Task does not return control to async block

I tried to reduce this to the smallest possible repro, but it's still a bit long-ish, my apologies. I have an F# project that references a C# project with code like the following. public static class CSharpClass { public static async Task…
Daniel
  • 47,404
  • 11
  • 101
  • 179
6
votes
2 answers

Use Post or PostAndAsyncReply with F#'s MailboxProcessor?

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…
user29439
6
votes
1 answer

API Rate Limiter Intermittent Hanging

I wrote a simple (I thought...) rate limiter to keep an event driven system under our licensed API hit limits. For some reason it seizes up sometimes after 400-500 requests are sent through. My best idea is that I have screwed up the wait function…
pluralMonad
  • 313
  • 1
  • 2
  • 7
6
votes
1 answer

f# mailboxprocessor - replying without waiting for delivery

I'm using an agent (MailboxProcessor) to do some stateful processing where a response is needed. The caller posts a message using MailboxProcessor.PostAndAsyncReply Within the agent, a response is given with AsyncReplyChannel.Reply However, I've…
Kasey Speakman
  • 4,511
  • 2
  • 32
  • 41
6
votes
1 answer

PostAndReply on a disposed MailboxProcessor

Is it possible to make PostAndAsyncReply return immediately when its MailboxProcessor is disposed (or otherwise stopped)? Or is there some "pattern" / best practice on how to safely use PostAndReply methods without creating deadlocks? Right now I…
stmax
  • 6,506
  • 4
  • 28
  • 45
5
votes
1 answer

Clarification of Events vs Observer vs MailboxProcessor in F#

I have a system, connected to financial markets, that makes a very heavy use of events. All the code is structured as a cascade of events with filters, aggregations, etc in between. Originally the system was written in C# and then ported to F#…
Thomas
  • 10,933
  • 14
  • 65
  • 136
5
votes
2 answers

F# MailboxProcessor limit parallelism

I'm new to F# and trying to experiment with the MailboxProcessor to ensure that state changes are done in isolation. In short, I am posting actions (immutable objects describing state chanage) to the MailboxProcessor, in the recursive function I…
eowind
  • 53
  • 1
  • 6
1
2 3 4 5