32 lines
800 B
C
32 lines
800 B
C
|
#ifndef _AsyncJsonCallbackResponse_H_
|
||
|
#define _AsyncJsonCallbackResponse_H_
|
||
|
|
||
|
#include <AsyncJson.h>
|
||
|
#include <ESPAsyncWebServer.h>
|
||
|
|
||
|
/*
|
||
|
* Listens for a response being destroyed and calls a callback during said distruction.
|
||
|
* used so we can take action after the response has been rendered to the client.
|
||
|
*
|
||
|
* Avoids having to fork ESPAsyncWebServer with a callback feature, but not nice!
|
||
|
*/
|
||
|
|
||
|
typedef std::function<void()> AsyncJsonCallback;
|
||
|
|
||
|
class AsyncJsonCallbackResponse: public AsyncJsonResponse {
|
||
|
|
||
|
private:
|
||
|
|
||
|
AsyncJsonCallback _callback;
|
||
|
|
||
|
public:
|
||
|
|
||
|
AsyncJsonCallbackResponse(AsyncJsonCallback callback, bool isArray=false) : _callback{callback}, AsyncJsonResponse(isArray) {}
|
||
|
~AsyncJsonCallbackResponse() {
|
||
|
_callback();
|
||
|
}
|
||
|
|
||
|
};
|
||
|
|
||
|
#endif // end _AsyncJsonCallbackResponse_H_
|