I have to post a simplified version of the code because it's quite big otherwise.
I have two threads running the same code in parallel, we can call them A and B.
I have an object which can be summarized as this:
let dataProcessor (settings) =
async {
let orderEventHandler = Handler<OrderData>(fun _ orderData ->
do some stuff with orderData
)
try
externalEvent.AddHandler(orderEventHandler)
// do a bunch of stuff in a loop
finally
externalEvent.RemoveHandler(orderEventHandler)
}
and then I start multiple instances of this:
Async.StartAsTask(dataprocessor settings1)
Async.StartAsTask(dataprocessor settings2)
These tasks get routinely created and destroyed.
The issue I am facing is that the first task is getting all the events, but the second one doesn't seem to get them reliably. I have printed out logs and some events simply do not arrive.
I realize it is a simplified version of the code, so the issue may not be apparent. My question is: am I missing something obvious here?