Added functions in promises to the future header. Review: https://reviews.apache.org/r/44547/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/9c3a8a58 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/9c3a8a58 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/9c3a8a58 Branch: refs/heads/master Commit: 9c3a8a58b644c567af3ca83a066ee5140f78050b Parents: be1fb94 Author: Anurag Singh <anurag.prakash.si...@gmail.com> Authored: Wed Apr 6 15:08:39 2016 -0400 Committer: Kapil Arya <ka...@mesosphere.io> Committed: Wed Apr 6 18:36:18 2016 -0400 ---------------------------------------------------------------------- 3rdparty/libprocess/include/process/future.hpp | 51 +++++++++++++++++++++ 1 file changed, 51 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/9c3a8a58/3rdparty/libprocess/include/process/future.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/process/future.hpp b/3rdparty/libprocess/include/process/future.hpp index ae4f2d6..9a335d1 100644 --- a/3rdparty/libprocess/include/process/future.hpp +++ b/3rdparty/libprocess/include/process/future.hpp @@ -1451,6 +1451,57 @@ bool Future<T>::fail(const std::string& _message) return result; } + +// Helper for setting a set of Promises. +template <typename T> +void setPromises(std::set<Promise<T>*>* promises, const T& t) +{ + foreach (Promise<T>* promise, *promises) { + promise->set(t); + delete promise; + } + promises->clear(); +} + + +// Helper for failing a set of Promises. +template <typename T> +void failPromises(std::set<Promise<T>*>* promises, const std::string& failure) +{ + foreach (Promise<T>* promise, *promises) { + promise->fail(failure); + delete promise; + } + promises->clear(); +} + + +// Helper for discarding a set of Promises. +template <typename T> +void discardPromises(std::set<Promise<T>*>* promises) +{ + foreach (Promise<T>* promise, *promises) { + promise->discard(); + delete promise; + } + promises->clear(); +} + + +// Helper for discarding an individual promise in the set. +template <typename T> +void discardPromises(std::set<Promise<T>*>* promises, const Future<T>& future) +{ + foreach (Promise<T>* promise, *promises) { + if (promise->future() == future) { + promise->discard(); + promises->erase(promise); + delete promise; + return; + } + } +} + } // namespace process { #endif // __PROCESS_FUTURE_HPP__