0

I've got a situation where I have two async methods that both have the same return type and one calls the other without changing the shape of the data.

public async Task<int> Foo() { return 1; }

public async Task<int> Bar() 
{ 
    return await Foo();
}

Is there any reason to use async/await in the Bar function or can I simply return the task created by the inner method?

So, for example, is this version of Bar more performant? Does it produce one less block?

public Task<int> Bar() 
{
    return Foo();
}

What's actually happening behind the scenes when async calls are chained in this way?

Mo09890
  • 174
  • 1
  • 9

1 Answers1

1

Stephen Cleary wrote about this, eliding the async.

There are a few issues to watch out for, the one that hit me the most was about exception handling.

I stopped removing it and now usually write async all along the chain.

H H
  • 263,252
  • 30
  • 330
  • 514