4 ms·
In your first code sample, I'm pretty sure you don't need the return await GetSession (provider, isLast, options, token); Unless there's more to the method, ju
by mfn 13y ago
In your first code sample, I'm pretty sure you don't need the return await GetSession (provider, isLast, options, token);
Unless there's more to the method, just remove the async modifier and directly return the task returned by GetSession.
- cmircea 13y agoawait will unwrap exceptions from the task object
- danabramov 13y agoExactly, and thus I'll be able to try next provider in the loop.
- danabramov 13y agoIf I did that, the code would always return at the first GetSession call. Instead, it unwraps exceptions, and while it propagates cancelations, it ignores other exceptions and tries other providers in turn. In fact, I could even use `break` or `continue` in the midst of async code, and there would be no problem. Also I just love using `try` and `finally` in async code—with callbacks, you have to do finalization from all error and success paths (which can be a lot of places).