Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:23

0001 //
0002 // Copyright (c) 2023 Klemens Morgenstern (klemens.morgenstern@gmx.net)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 
0008 #ifndef BOOST_BEAST_TEST_IMMEDIATE_EXECUTOR_HPP
0009 #define BOOST_BEAST_TEST_IMMEDIATE_EXECUTOR_HPP
0010 
0011 #include <boost/asio/any_io_executor.hpp>
0012 
0013 namespace boost
0014 {
0015 namespace beast
0016 {
0017 namespace test
0018 {
0019 
0020 /** A immediate executor that directly invokes and counts how often that happened. */
0021 
0022 class immediate_executor
0023 {
0024     std::size_t &count_;
0025   public:
0026     immediate_executor(std::size_t & count) noexcept : count_(count) {}
0027 
0028     asio::execution_context &query(asio::execution::context_t) const
0029     {
0030         BOOST_ASSERT(false);
0031         return *static_cast<asio::execution_context*>(nullptr);
0032     }
0033 
0034     constexpr static asio::execution::blocking_t
0035     query(asio::execution::blocking_t) noexcept
0036     {
0037         return asio::execution::blocking_t::never_t{};
0038     }
0039 
0040     constexpr static asio::execution::relationship_t
0041     query(asio::execution::relationship_t) noexcept
0042     {
0043         return asio::execution::relationship_t::fork_t{};
0044     }
0045     // this function takes the function F and runs it on the event loop.
0046     template<class F>
0047     void
0048     execute(F f) const
0049     {
0050         count_++;
0051         std::forward<F>(f)();
0052     }
0053 
0054     bool
0055     operator==(immediate_executor const &other) const noexcept
0056     {
0057         return true;
0058     }
0059 
0060     bool
0061     operator!=(immediate_executor const &other) const noexcept
0062     {
0063         return false;
0064     }
0065 };
0066 
0067 }
0068 }
0069 }
0070 
0071 #endif //BOOST_BEAST_TEST_IMMEDIATE_EXECUTOR_HPP