electron/shell/app/uv_task_runner.h

46 lines
1.3 KiB
C
Raw Normal View History

2015-09-03 02:28:50 +00:00
// Copyright (c) 2015 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_APP_UV_TASK_RUNNER_H_
#define SHELL_APP_UV_TASK_RUNNER_H_
2015-09-03 02:28:50 +00:00
#include <map>
#include "base/callback.h"
#include "base/location.h"
2015-09-03 02:28:50 +00:00
#include "base/single_thread_task_runner.h"
#include "uv.h" // NOLINT(build/include_directory)
2015-09-03 02:28:50 +00:00
namespace electron {
2015-09-03 02:28:50 +00:00
// TaskRunner implementation that posts tasks into libuv's default loop.
class UvTaskRunner : public base::SingleThreadTaskRunner {
public:
explicit UvTaskRunner(uv_loop_t* loop);
// base::SingleThreadTaskRunner:
bool PostDelayedTask(const base::Location& from_here,
base::OnceClosure task,
2015-09-03 02:28:50 +00:00
base::TimeDelta delay) override;
bool RunsTasksInCurrentSequence() const override;
2018-04-18 01:44:10 +00:00
bool PostNonNestableDelayedTask(const base::Location& from_here,
base::OnceClosure task,
base::TimeDelta delay) override;
2015-09-03 02:28:50 +00:00
private:
~UvTaskRunner() override;
2015-09-03 02:28:50 +00:00
static void OnTimeout(uv_timer_t* timer);
static void OnClose(uv_handle_t* handle);
2015-09-03 02:28:50 +00:00
uv_loop_t* loop_;
std::map<uv_timer_t*, base::OnceClosure> tasks_;
2015-09-03 02:28:50 +00:00
DISALLOW_COPY_AND_ASSIGN(UvTaskRunner);
};
} // namespace electron
2015-09-03 02:28:50 +00:00
2019-06-19 20:56:58 +00:00
#endif // SHELL_APP_UV_TASK_RUNNER_H_