Created
December 3, 2015 08:14
-
-
Save Danthar/2b1e421321a41bf27df5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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