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. The get member function waits (by calling wait ()) until the shared state is ready, then retrieves the value stored in the shared state (if any) Right after calling this function, valid () is false If valid () is false before the call to this function, the behavior is undefined. Checks if the future refers to a shared state
Returned by std::promise::get_future (), std::packaged_task::get_future () or std::async ()) until the first time get () or share () is called If the future is the result of a call to std::async that used lazy evaluation, this function returns immediately without waiting This function may block for longer than timeout_duration due to scheduling or resource contention delays The standard recommends that a steady clock is used to measure the duration. Specifies state of a future as returned by wait_for and wait_until functions of std::future and std::shared_future Unlike std::future, which is only moveable (so only one instance can refer to any particular asynchronous result), std::shared_future is copyable and multiple shared future objects may refer to the same shared state
Future (const future &) = delete Future & operator =(const future &) = delete Future & operator =(future &&) noexcept Shared_future <r> share () noexcept // retrieving the value /* see description */ get () // functions to check state bool valid () const noexcept
A future represents the result of an asynchronous operation, and can have two states 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. Ensure_future vs create_task ensure_future is a method to create task from coroutine Create_task is an abstract method of abstracteventloop Different event loops can implement this function different ways.
Multiple std::shared_future objects may reference the same shared state, which is not possible with std::future After calling share on a std::future, valid() == false.
OPEN