Sometimes, you have some code that will be run asynchronously at some point in the future. You want to know when that code is done running. Here's what you can do now:
But what if you want to have access to `fut` before you actually schedule task? For example:
But this code won't compile, because SharedSemiFuture has no default constructor. Instead, we would need to make _isDoneFuture an optional, and only give it a value when the task is actually scheduled. (Yuck!) What we want is a future that is readied when task is run, that can safely be created and used even before task is scheduled.
This is what packaged_task does :https://en.cppreference.com/w/cpp/thread/packaged_task
We could rewrite our above example as follows:
Futures extracted via _task.getFuture() will be readied when task has executed and contain the value returned by task (or exceptions it threw).