1 // Copyright (c) 2016 Klemens D. Morgenstern
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #ifndef BOOST_PROCESS_DETAIL_ON_EXIT_HPP_
7 #define BOOST_PROCESS_DETAIL_ON_EXIT_HPP_
9 #include <boost/process/detail/config.hpp>
11 #if defined(BOOST_POSIX_API)
12 #include <boost/process/detail/posix/on_exit.hpp>
13 #elif defined(BOOST_WINDOWS_API)
14 #include <boost/process/detail/windows/on_exit.hpp>
20 namespace boost { namespace process { namespace detail {
22 inline std::function<void(int, const std::error_code &)> on_exit_from_future(std::future<int> &f)
24 std::shared_ptr<std::promise<int>> promise = std::make_shared<std::promise<int>>();
25 f = promise->get_future();
26 return [promise](int code, const std::error_code & ec)
29 promise->set_exception(
30 std::make_exception_ptr(process_error(ec, "on_exit failed with error"))
33 promise->set_value(code);
40 api::on_exit_ operator= (const std::function<void(int, const std::error_code&)> & f) const {return f;}
41 api::on_exit_ operator()(const std::function<void(int, const std::error_code&)> & f) const {return f;}
43 api::on_exit_ operator= (std::future<int> &f) const {return on_exit_from_future(f);}
44 api::on_exit_ operator()(std::future<int> &f) const {return on_exit_from_future(f);}
49 constexpr static ::boost::process::detail::on_exit_ on_exit{};
53 #endif /* INCLUDE_BOOST_PROCESS_WINDOWS_ON_EXIT_HPP_ */