Consider the following C# code:
async Task DoSomethingAsync()
{
if (m_f)
return;
await DoSomethingInternalAsync();
}
What the compiler turns this into is a task returning call where if m_f is true, the task completes immediately and if not, it "delegates" the async operation to DoSomethingInternalAsync().
Now, how do I do this in c++? The code should look something like this:
task<void> DoSomethingAsync()
{
if (m_f)
return [[What do I return here so the task is complete (.then called immediately)?!]];
return DoSomethingInternalAsync();
}
Edit1: In C#, I can use a TaskCompletionSource<> to do the same thing, but w/o using the async keyword - essentially create a completed Task.
Another way to do this is task_from_result. You can use concurrency::task_from_result()
for task<void>
methods and concurrency::task_from_result(theReturnValue)
for task<T>
methods. I believe this is new starting in Visual Studio 2013.