c# - .NET async/await: in this case should I return something? -
in case this, task return instantly because of conditions:
public async task test(list<int> testlist) { if (testlist.count() == 0) return; // await uploadlistasync(testlist); } is correct return;, should use task.fromresult(false);, or there more correct way?
when you're using async, can't return task explicitly (see edit) - return value has been boxed compiler return value of task. thus, async methods should behave other methods , return if need bail out of logic early.
edit: 1 time can return task during async if return type task<task..., still returning inner task, not outer, since compiler has done same wrapping. should rare use case opposed await-ing chain of tasks
Comments
Post a Comment