0

Currently, I spawn a bunch of actors to do some long running task. I put these into a List, then call Task.WaitAll() to collect the results.

However, I want to collect the results as each Actor completes its task (rather than wait for every actor to finish and aggregate it at the end).

I was thinking about using reliable collections, but how do I share a reliable collection between all actors?

Thanks!

Ambrose Leung
  • 3,704
  • 2
  • 25
  • 36

1 Answers1

1

Actors are separate entities by design so you can't simply 'share' a collection between several instances. A couple of workarounds that cross my mind -

  • Spawn a dedicated actor with a fixed id and make other actors to communicate with this one when they finish their job
  • Create a separate stateful service that your actors will be accessing to store the required data
  • Have a separate resource, like EventHub, to listen for the events that actors will generate upon tasks completion
Kiryl
  • 1,416
  • 9
  • 21
  • I ended up using a dedicated actor to collect the results so that it can display a status/write to the database at an interval I can control. Thanks again. – Ambrose Leung Sep 09 '17 at 16:16