electron/atom/browser/microtasks_runner.h
Nitish Sakhawalkar 0c711f690e fix: add microtask runner and fix promise test (#15071)
* fix: Promise resolution and unit test

* Update to use microtask runner

* Address review
2018-10-16 02:26:47 +11:00

36 lines
1.1 KiB
C++

// Copyright (c) 2018 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ATOM_BROWSER_MICROTASKS_RUNNER_H_
#define ATOM_BROWSER_MICROTASKS_RUNNER_H_
#include "base/message_loop/message_loop.h"
namespace v8 {
class Isolate;
}
namespace atom {
// 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.
class MicrotasksRunner : public base::MessageLoop::TaskObserver {
public:
explicit MicrotasksRunner(v8::Isolate* isolate);
// base::MessageLoop::TaskObserver
void WillProcessTask(const base::PendingTask& pending_task) override;
void DidProcessTask(const base::PendingTask& pending_task) override;
private:
v8::Isolate* isolate_;
};
} // namespace atom
#endif // ATOM_BROWSER_MICROTASKS_RUNNER_H_