microtasks_runner.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (c) 2018 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef SHELL_BROWSER_MICROTASKS_RUNNER_H_
  5. #define SHELL_BROWSER_MICROTASKS_RUNNER_H_
  6. #include "base/task/task_observer.h"
  7. namespace v8 {
  8. class Isolate;
  9. }
  10. namespace electron {
  11. // Microtasks like promise resolution, are run at the end of the current
  12. // task. This class implements a task observer that runs tells v8 to run them.
  13. // Microtasks runner implementation is based on the EndOfTaskRunner in blink.
  14. // Node follows the kExplicit MicrotasksPolicy, and we do the same in browser
  15. // process. Hence, we need to have this task observer to flush the queued
  16. // microtasks.
  17. class MicrotasksRunner : public base::TaskObserver {
  18. public:
  19. explicit MicrotasksRunner(v8::Isolate* isolate);
  20. // base::TaskObserver
  21. void WillProcessTask(const base::PendingTask& pending_task) override;
  22. void DidProcessTask(const base::PendingTask& pending_task) override;
  23. private:
  24. v8::Isolate* isolate_;
  25. };
  26. } // namespace electron
  27. #endif // SHELL_BROWSER_MICROTASKS_RUNNER_H_