Futures and Promises

suggest change

Versions

Introduction

Promises and futures pass one result, either a value or an exception, from the producer to the consumer. Those two sides are often different threads, but they do not have to be.

A std::promise is set by the code that produces the result.

A std::future retrieves that result with get(), which rethrows a stored exception. wait(), wait_for(), and wait_until() block until the result is ready. valid() only reports whether the future refers to a shared state; it does not report whether that state is ready.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents