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