Skip to content

Instantly share code, notes, and snippets.

@Danthar
Created December 3, 2015 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Danthar/2b1e421321a41bf27df5 to your computer and use it in GitHub Desktop.
Save Danthar/2b1e421321a41bf27df5 to your computer and use it in GitHub Desktop.
class AskAggregator<TReq, TRep> : ReceiveActor
{
public AskAggregator(IActorRef askFor, IActorRef replyTo, IEnumerable<TReq> items)
{
var requestCount = items.Count();
var replies = new HashSet<TRep>();
foreach (var request in items)
askFor.Tell(request);
Receive<TRep>(_ => Sender.Equals(askFor), reply =>
{
replies.Add(reply);
requestCount--;
if (requestCount <= 0)
{
replyTo.Tell(new AggregatedReply(replies));
Context.Stop(Self);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment