- std::future - cppreference. com
The class template std::future provides a mechanism to access the result of asynchronous operations: An asynchronous operation (created via std::async, std::packaged_task, or std::promise) can provide a std::future object to the creator of that asynchronous operation The creator of the asynchronous operation can then use a variety of methods to query, wait for, or extract a value from the std
- What is a Future and how do I use it? - Stack Overflow
A future represents the result of an asynchronous operation, and can have two states: uncompleted or completed Most likely, as you aren't doing this just for fun, you actually need the results of that Future<T> to progress in your application You need to display the number from the database or the list of movies found
- C++: Use future. get with timeout and without blocking
But you might want to have a queue of completed jobs to check, instead of a single future This queue would only be consumed by your main thread and can be implemented with a non-blocking thread-safe "try_get" call to get next completed jobs As others commented, you may want to wrap your time-saving logic in a job dispatcher class or similar
|