1

Will the following line...

var isAuthorized = (await _authorizationService.AuthorizeAsync(...)).Succeeded;

...result in an asynchronous execution which differs to the caller until the result of AuthorizeAsync(...) is found, or will it block the thread until the result is found? Why or why not?

According to this question for vb.net, such an expression is known as non-literal. Based on questions and answers from Fluently Calling Await without Parentheses and How to Design Fluent Async Operations, this statement seems fine. However, I want to be sure, and know why from the documentation that makes this particular case clear.

Denis G. Labrecque
  • 1,023
  • 13
  • 29

1 Answers1

8

Here:

var object = _authorizationService.AuthorizeAsync(...)

object = the task itself.


Here:

var object = await _authorizationService.AuthorizeAsync(...)

object = the evaluation of the task, aka it's result.


Here

var object = (await _authorizationService.AuthorizeAsync(...)).Succeeded;

you're playing with the evaluation. (It won't block anything, it's not like using _authorizationService.AuthorizeAsync(...).Result).


This:

var object = (await _authorizationService.AuthorizeAsync(...)).Succeeded

is this, but in a single line

var aux = await _authorizationService.AuthorizeAsync(...);
var object = aux.Succeeded;
Dorin Baba
  • 1,578
  • 1
  • 11
  • 23