Replies: 9 comments
-
How would this deal with exceptions? What happens if the first task to complete fails with an exception? Would that rethrow the exception? What happens when the second task to complete fails? Would that ignore the exception? Currently, I believe the language never ignores exceptions (the library might, but that's not the same thing).
I'm not sure |
Beta Was this translation helpful? Give feedback.
-
If the first task fails with an exception, the containing task also fails. If the second task fails, we ignore it just like |
Beta Was this translation helpful? Give feedback.
-
I know what it means but the syntax |
Beta Was this translation helpful? Give feedback.
-
you're waiting for a true, makes sense for me :) |
Beta Was this translation helpful? Give feedback.
-
@alrz You're waiting for any bool value, yes. Typically you only wait for an awaitable. Just don't put a GetAwaiter extension method on bool 😆 |
Beta Was this translation helpful? Give feedback.
-
The awaitable on bool would be awaited if you use |
Beta Was this translation helpful? Give feedback.
-
Actually if that's what |
Beta Was this translation helpful? Give feedback.
-
I'm not native so I'm not sure how it exactly reads but I think that's the most sensible syntax to use here.
I meant that we actually wait until the awaitable returns, from there. it's just a constant pattern. |
Beta Was this translation helpful? Give feedback.
-
@alrz I also think it reads oddly. For comparison, imagine a strange (and incorrectly implemented) TResult WaitFor<TResult>(Func<bool> condition, Func<TResult> whenTrue)
{
var @true = condition();
while (@true is false)
{
Thread.Sleep(100); // obviously broken
@true = condition();
}
return whenTrue();
}
var message = WaitFor(() => true, () => "always"); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
If the target expression is awaitable, we may use
await
to await that object.This is specifically useful with tuple patterns to do a pattern-match in parallel.
Implementing something like this with
WhenAny
is not as effective (besides that every task must be of a same type) you wouldn't know that which task is completed and you have to compare the returned task with each one of them. Also this would work with any awaitable includingIOservable<T>
via Rx.Related: dotnet/roslyn#5187, http://tomasp.net/blog/fsharp-variations-joinads.aspx
Beta Was this translation helpful? Give feedback.
All reactions