Fork of the excellent esp8266-react - https://github.com/rjwats/esp8266-react
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
800 B

  1. #ifndef _AsyncJsonCallbackResponse_H_
  2. #define _AsyncJsonCallbackResponse_H_
  3. #include <ESPAsyncWebServer.h>
  4. #include <AsyncJson.h>
  5. /*
  6. * Listens for a response being destroyed and calls a callback during said distruction.
  7. * used so we can take action after the response has been rendered to the client.
  8. *
  9. * Avoids having to fork ESPAsyncWebServer with a callback feature, but not nice!
  10. */
  11. typedef std::function<void()> AsyncJsonCallback;
  12. class AsyncJsonCallbackResponse: public AsyncJsonResponse {
  13. private:
  14. AsyncJsonCallback _callback;
  15. public:
  16. AsyncJsonCallbackResponse(AsyncJsonCallback callback, bool isArray=false) : AsyncJsonResponse(isArray), _callback{callback} {}
  17. ~AsyncJsonCallbackResponse() {
  18. _callback();
  19. }
  20. };
  21. #endif // end _AsyncJsonCallbackResponse_H_