template<class T>
class simgrid::kernel::Promise< T >
Producer side of a simgrid::kernel::Future.
A Promise is connected to some Future
and can be used to set its result.
Similar to std::promise
// Create a promise and a future: auto promise = std::make_shared<simgrid::kernel::Promise<T>>(); auto future = promise->get_future();
SIMIX_timer_set(date, [promise] { try { int value = compute_the_value(); if (value < 0) throw std::logic_error("Bad value"); // Whenever the operation is completed, we set the value // for the future: promise.set_value(value); } catch (...) { // If an error occured, we can set an exception which // will be throwed buy future.get(): promise.set_exception(std::current_exception()); } });
// Return the future to the caller: return future;