DoLaterHandler.cpp 389 B

12345678910111213141516171819202122232425262728
  1. #include "DoLaterHandler.h"
  2. DoLaterHandler::DoLaterHandler()
  3. {
  4. action = []() {};
  5. }
  6. DoLaterHandler::~DoLaterHandler()
  7. {
  8. action();
  9. }
  10. void DoLaterHandler::addTodo(std::function<void()> newAction)
  11. {
  12. std::function<void()> oldAction = action;
  13. this->action = [oldAction, newAction]()
  14. {
  15. oldAction();
  16. newAction();
  17. };
  18. }
  19. void DoLaterHandler::execute()
  20. {
  21. action();
  22. action = []() {};
  23. }