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

Document how error handling works #76

Open
acjay opened this issue Jun 20, 2014 · 6 comments
Open

Document how error handling works #76

acjay opened this issue Jun 20, 2014 · 6 comments
Assignees
Labels

Comments

@acjay
Copy link

acjay commented Jun 20, 2014

How are failed futures handled? Does the whole async block just fail? Is there a way to handle individual failed awaits within one async block, or is the only solution there to nest async blocks? If that's the case, perhaps a tryAwait that returns a Try would be helpful. In any case, a couple examples in the docs would be great. Thanks

@retronym retronym added this to the 0.9.3 milestone Jul 21, 2014
@retronym retronym self-assigned this Jul 21, 2014
@justjoheinz
Copy link

I would also be interested in this.

@retronym retronym modified the milestones: 0.9.3, 0.9.4 Jan 8, 2015
@retronym retronym removed this from the 0.9.4 milestone Jul 7, 2015
@danarmak
Copy link

The code behaves as if the call to await throws the exception with which the awaited Future failed.

While await under try/catch is currently unsupported, one alternative would be to write await(future recover ...).

tryAwait would be equivalent to this simple function: def tryAwait[T](fut: Future[T]): Try[T] = await(fut map Success.apply recover PartialFunction(Failure.apply)

However, that won't work because await can't be used inside a function; a macro is needed. I'll submit a PR with that macro if you'd be interested in including tryAwait in the project.

(From what I've read of the code, most of the work will be to construct the right kind of Tryy. Why is there even a Tryy type if both implementations use scala.util.Try?)

@pkolaczk
Copy link

+1 to tryAwait at least until proper try/catch handling is supported

@acjay
Copy link
Author

acjay commented Jan 7, 2016

I'll submit a PR with that macro if you'd be interested in including tryAwait in the project.

This would be much appreciated!

@ebruchez
Copy link

ebruchez commented Nov 2, 2016

I was playing with async/await and this is one of the first questions that popped up. So 👍 to improve this.

@ebruchez
Copy link

ebruchez commented Nov 3, 2016

FWIW I used @danarmak's solution above:

await(kittens() map Success.apply recover PartialFunction(Failure.apply)) match {
  case Failure(t)  // ...
  case Success(v)  // ...
}

But a tryAwait shortcut would be good.

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

No branches or pull requests

6 participants