I want to create a new task that is already completed from the given result. My current workaround is:
return concurrency::task<T>([]{return result;});
Is there anything better?
The problem is with the following code:
concurrency::task<bool> foo()
{
if (smth)
// the result is
return (foo_other() && foo_other2()).then([](std::vector<bool> results) {...});
//return false;
return concurrency::task<bool>([]{return false;});
}
As you can see, my function is asynchronous and it depends on another asynchronous function. But sometimes I can exit the app e.g. if the async task was already done. In that case I need to return a continuable task which returns a specified result.
You can create a completed task as follows:
concurrency::task_from_result<bool>(false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With