petabridge / akka-bootcamp

Self-paced training course to learn Akka.NET fundamentals from scratch
http://learnakka.net/
Apache License 2.0
1.04k stars 1.57k forks source link

Unit 3 Lesson 4. Why do we need to capture Sender into a local variable before passing it to PipeTo? #305

Open ghost opened 4 years ago

ghost commented 4 years ago

Capturing Sender into local variable makes no sense here. PipeTo is executed sync. If we were to use Sender in ContinueWith lambda, then it would be necessary to capture, but why capture it here? This confuses me. And the importance of capturing Sender is repeated many times on different pages. Makes me think that either I am missing smth, or whoever wrote this made a mistake.

Receive<BeginProcessFeed>(feed =>
{
    //instance variable for closure
    var senderClosure = Sender; 
    SendMessage(string.Format("Downloading {0} for RSS/ATOM processing...", feed.FeedUri));

    //reply back to the sender
    _feedFactory.CreateFeedAsync(feed.FeedUri).PipeTo(senderClosure);
});