Reputation: 2233
I can't seem to understand why this won't work. I've searched endlessly and don't see how my example below doesn't kick off an asynchronous operation.
void Folder::NewFileAction()
{
if (Folder::Match)
{
LOG(LOG_INFO) << "New file detected. Compressing";
auto Compress = async(launch::async, &ZipFile, Folder::FilePath);
}
}
Shouldn't this kick off an asynchronous operation in another thread? Is there a flag I have to enable in Visual Studio 2015?
Thank you
Upvotes: 4
Views: 458
Reputation: 18441
std::async
returns a std::future
object. Since Compress
is local object (of type std::future
), and will go out of scope. Since this is only object holding the async
return result, the destructor will keep on waiting. You should keep such object(s) in member of this class (a vector<future>
may be).
Upvotes: 7