How to check if a std::async task is finished?
Use future::wait_for()
. You can specify a timeout, and after that, get a status code.
Example:
task.wait_for(std::chrono::seconds(1));
This will return future_status::ready
, future_status::deferred
or future_status::timeout
, so you know the operation's status. You can also specify a timeout of 0 to have the check return immediately as soon as possible.