1 #pragma once 2 3 #include "http_response.hpp" 4 5 #include <functional> 6 7 namespace bmcweb 8 { 9 10 /** 11 * AsyncResp 12 * Gathers data needed for response processing after async calls are done 13 */ 14 15 class AsyncResp 16 { 17 public: 18 AsyncResp(crow::Response& response) : res(response) 19 {} 20 21 AsyncResp(crow::Response& response, std::function<void()>&& function) : 22 res(response), func(std::move(function)) 23 {} 24 25 AsyncResp(const AsyncResp&) = delete; 26 AsyncResp(AsyncResp&&) = delete; 27 28 ~AsyncResp() 29 { 30 if (func && res.result() == boost::beast::http::status::ok) 31 { 32 func(); 33 } 34 35 res.end(); 36 } 37 38 crow::Response& res; 39 std::function<void()> func; 40 }; 41 42 } // namespace bmcweb 43