Daily bit(e) of C++ #157, The C++11 simple deferred execution utility: std::async.
In my received email, there is a wrong code that I past it in the below:
```
// We can use async, to defer execution of code until the end of the scope
{
FILE *file = fopen("/dev/null", "r");
auto deferred_close = std::async(std::launch::deferred, [file](){
fclose(file);
});
} // destructor for deferred_close runs and closes the file
But it doesn't work, and we should call get() or wait() method for execution of lambda function.
Yes, it was a mistake that managed to survive into the example. The updated code is correct.
do people really use it in production? for a test-scenario and quick and dirty async threading, it's nice but the lack of ctrl makes it less attractive for real production code. what do you think?
Not really, it would be much better if the first argument was a customization point.
I think we are supposed to get something like std::async with executors.
In my received email, there is a wrong code that I past it in the below:
```
// We can use async, to defer execution of code until the end of the scope
{
FILE *file = fopen("/dev/null", "r");
auto deferred_close = std::async(std::launch::deferred, [file](){
fclose(file);
});
} // destructor for deferred_close runs and closes the file
```
But it doesn't work, and we should call get() or wait() method for execution of lambda function.
Yes, it was a mistake that managed to survive into the example. The updated code is correct.
do people really use it in production? for a test-scenario and quick and dirty async threading, it's nice but the lack of ctrl makes it less attractive for real production code. what do you think?
Not really, it would be much better if the first argument was a customization point.
I think we are supposed to get something like std::async with executors.