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() 24 { 25 if (func && res.result() == boost::beast::http::status::ok) 26 { 27 func(); 28 } 29 30 res.end(); 31 } 32 33 crow::Response& res; 34 std::function<void()> func; 35 }; 36 37 } // namespace bmcweb 38