I have a method with the following signature:
public async Task<Result> CreateAsync(T entity)
{
try
{
await _c.CreateItemAsync(entity);
return Result.Ok();
}
catch (Exception e)
{
return Handle(e); // returns a `Result`
}
}
_c is a Container for CosmosDB.
Now, I have another method like this:
public Task<Result> CreateUserAsync(User user)
{
var userEntity = new UserEntity { Id = user.Id, Name = user.Name };
return CreateAsync(userEntity);
}
Result.Ok() is a very simple static method of a custom class Result:
class Result
{
public static Result Ok() { return new Result(); }.
}
So, I have two methods, one being Task<Result> CreateUserAsync(User user), which returns a simple Task, without awaiting anything inside it, but the other task that I call at the end return CreateAsync(userEntity); awaits stuff inside it.
So to my understanding, CreateAsync() should remain as a Task return type, because it performs async stuff inside it, but does the method I call it from (that is CreateUserAsync()) needs to remain Task as well, or can it become a ValueTask?