Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional PipeTo completion handlers #1381

Merged
merged 1 commit into from
Oct 16, 2015
Merged

Conversation

emilingerslev
Copy link
Contributor

Added an optional success and failure handler to PipeTo, to simplify use of Tasks. PipeTo falls back to original behavior either handler isn't supplied.

Some examples:

Context.ActorSelection("akka.tcp://remote@remote:1234/user/PingActor")
    .ResolveOne(TimeSpan.FromSeconds(1))
    .PipeTo(Self,
        success: x => new PleasePing(x),
        failure: e => new TryAgainLater(e.ToString()));

actorRef.Ask<Pong>(new Ping())
    .PipeTo(Self,
        failure: e => new TryAgainLater(e.ToString()));

Added an optional success and failure handler to PipeTo, to simplify
use of Tasks. PipeTo falls back to original behavior when not supplied.
@Horusiath
Copy link
Contributor

👍 Great idea! Mapping result or failure before sending in PipeTo is quite common pattern. It would be nice to have this support build into Akka itself.

@rogeralsing
Copy link
Contributor

This is great!!

@emilingerslev
Copy link
Contributor Author

Glad you like it! It works perfect in what I've working on.

I'm not sure though how much is allowed in the Task.ContinueWith handling? Can you say something like its best practice to only do conversions to new message types or would something like this be alright?:

Context.ActorSelection("akka.tcp://remote@remote:1234/user/PingActor")
    .ResolveOne(TimeSpan.FromSeconds(1))
    .PipeTo(Self,
        success: x => x.Ask<Pong>(new Ping()),
        failure: e => new TryAgainLater(e.ToString()));

I think the syntax becomes more dirty and harder to read, but it would be great with some guidelines.
I would gladly help updating the docs too.

@emilingerslev
Copy link
Contributor Author

BTW, do you know why the build has gone rogue like?

Horusiath added a commit that referenced this pull request Oct 16, 2015
Add optional PipeTo completion handlers
@Horusiath Horusiath merged commit ca7848a into akkadotnet:dev Oct 16, 2015
@Aaronontheweb
Copy link
Member

Reverted this- please add unit tests and resubmit

@emilingerslev
Copy link
Contributor Author

Alright, I'll look into creating a few tests for this

@Aaronontheweb
Copy link
Member

Thanks!

@emilingerslev
Copy link
Contributor Author

Resubmitted it as #1383

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants