microtasks_runner.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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 ELECTRON_SHELL_BROWSER_MICROTASKS_RUNNER_H_
  5. #define ELECTRON_SHELL_BROWSER_MICROTASKS_RUNNER_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "base/task/task_observer.h"
  8. namespace v8 {
  9. class Isolate;
  10. }
  11. namespace electron {
  12. // Microtasks like promise resolution, are run at the end of the current
  13. // task. This class implements a task observer that runs tells v8 to run them.
  14. // Microtasks runner implementation is based on the EndOfTaskRunner in blink.
  15. // Node follows the kExplicit MicrotasksPolicy, and we do the same in browser
  16. // process. Hence, we need to have this task observer to flush the queued
  17. // microtasks.
  18. class MicrotasksRunner : public base::TaskObserver {
  19. public:
  20. explicit MicrotasksRunner(v8::Isolate* isolate);
  21. // base::TaskObserver
  22. void WillProcessTask(const base::PendingTask& pending_task,
  23. bool was_blocked_or_low_priority) override;
  24. void DidProcessTask(const base::PendingTask& pending_task) override;
  25. private:
  26. raw_ptr<v8::Isolate> isolate_;
  27. };
  28. } // namespace electron
  29. #endif // ELECTRON_SHELL_BROWSER_MICROTASKS_RUNNER_H_