DoomerDGR8
DoomerDGR8

Reputation: 5042

new JsonResult() in async API

I'm wondering if I should make this API a non-async or somehow get await in the method body:

[Route("identity")]
[Authorize]
public class IdentityController : ControllerBase
{
    [HttpGet]
    public async Task<IActionResult> GetAsync() => new JsonResult(from c in User.Claims select new { c.Type, c.Value });
}

I'm not able to find a ready to use solution where JsonResult can return awaited. Any help, remove async, or just ignore the warning?

Upvotes: 0

Views: 548

Answers (1)

Martin Staufcik
Martin Staufcik

Reputation: 9492

When the async method lacks 'await' operators it will run synchronously, just as the warning says. There is no gain making it asynchronous.

To remove this warning you could make this method synchronous:

[HttpGet]
public IActionResult Get() => new JsonResult(from c in User.Claims select new { c.Type, c.Value });

Upvotes: 1

Related Questions