How to determine if std :: future has a value?

Please note that this is different from the call valid(). valid()indicates whether the future has a correct general state in general, however I want to know if the meaning is set for the future (i.e. through std::promise::set_value).

There is a method wait_for, however, I do not want the calling thread to block at all, I just want to check for the value. Theoretically, I could call wait_forzero duration, but I don’t know if this is really the preferred way to do this, and I'm not sure if the expected behavior occurs when calling wait_forwith zero duration.

+4
source share
1 answer

The purpose of using std :: future is to be able to execute the task asynchronously. This way, only call call get () in the future when you need a value, because it locks the thread until the future is ready, and then returns the value.

0
source

All Articles