I'm familiar with async/await, returning threads to the pool on an await with an async function. I can see the benefit of this in a controller method returning the thread for another API requests, and in any 3rd party API calls, such as AWS.
But is there any benefit in using it throughout the entire call stack? Consider this pseudocode example:
public class MyController
public async Task<IActionResult> MyFirstFunction()
{
var result = await _myHandler.MySecondFunction();
...
return Ok();
}
}
public class MyHandler
public Task<bool> MySecondFunction()
{
...
return thirdPartyHandler.ThirdPartyFunction(object);
}
}
public class ThirdPartyHandler
public async Task<bool> ThirdPartyFunction(Object object)
{
return await thirdParty.ExternalFunctionAsync(object);
}
}
Would this code not achieve the same thing as having made the 'MySecondFunction' function async, and awaited the ThirdPartyFunction() function call, with less overhead of having to deal with capturing a context and returning a thread to the pool etc?
Admittedly the MyHandler and ThirdPartyHandler are somewhat redundant and could be combined