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.
|
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#ifndef SHELL_BROWSER_MICROTASKS_RUNNER_H_
|
|
|
|
#define SHELL_BROWSER_MICROTASKS_RUNNER_H_
|
2018-10-15 15:26:47 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2018-10-15 15:26:47 +00:00
|
|
|
|
|
|
|
// 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:
|
|
|
|
v8::Isolate* isolate_;
|
|
|
|
};
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2018-10-15 15:26:47 +00:00
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#endif // SHELL_BROWSER_MICROTASKS_RUNNER_H_
|