2018-10-15 15:26:47 +00:00
|
|
|
// Copyright (c) 2018 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_MICROTASKS_RUNNER_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_MICROTASKS_RUNNER_H_
|
2018-10-15 15:26:47 +00:00
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2019-08-24 01:14:23 +00:00
|
|
|
#include "base/task/task_observer.h"
|
2018-10-15 15:26:47 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
class Isolate;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
|
|
|
// Microtasks like promise resolution, are run at the end of the current
|
|
|
|
// task. This class implements a task observer that runs tells v8 to run them.
|
|
|
|
// Microtasks runner implementation is based on the EndOfTaskRunner in blink.
|
|
|
|
// Node follows the kExplicit MicrotasksPolicy, and we do the same in browser
|
|
|
|
// process. Hence, we need to have this task observer to flush the queued
|
|
|
|
// microtasks.
|
2019-08-24 01:14:23 +00:00
|
|
|
class MicrotasksRunner : public base::TaskObserver {
|
2018-10-15 15:26:47 +00:00
|
|
|
public:
|
|
|
|
explicit MicrotasksRunner(v8::Isolate* isolate);
|
|
|
|
|
2019-08-24 01:14:23 +00:00
|
|
|
// base::TaskObserver
|
2019-12-11 00:22:35 +00:00
|
|
|
void WillProcessTask(const base::PendingTask& pending_task,
|
|
|
|
bool was_blocked_or_low_priority) override;
|
2018-10-15 15:26:47 +00:00
|
|
|
void DidProcessTask(const base::PendingTask& pending_task) override;
|
|
|
|
|
|
|
|
private:
|
2023-05-11 20:07:39 +00:00
|
|
|
raw_ptr<v8::Isolate> isolate_;
|
2018-10-15 15:26:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace electron
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_MICROTASKS_RUNNER_H_
|