xref: /openbmc/bmcweb/include/async_resp.hpp (revision a778c026)
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 
20     AsyncResp(crow::Response& response, std::function<void()>&& function) :
21         res(response), func(std::move(function))
22     {
23     }
24 
25     ~AsyncResp()
26     {
27         if (func && res.result() == boost::beast::http::status::ok)
28         {
29             func();
30         }
31 
32         res.end();
33     }
34 
35     crow::Response& res;
36     std::function<void()> func = 0;
37 };
38 
39 } // namespace bmcweb
40