How do I create concurrency::task from result?
c++, c++11, ppl, task
Solution
You can create a completed task as follows:
concurrency::task_from_result<bool>(false);
Problem
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.