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.
|
|
|
|
|
|
|
|
#ifndef ATOM_APP_UV_TASK_RUNNER_H_
|
|
|
|
#define ATOM_APP_UV_TASK_RUNNER_H_
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include "base/callback.h"
|
2017-12-17 23:56:18 +00:00
|
|
|
#include "base/location.h"
|
2015-09-03 02:28:50 +00:00
|
|
|
#include "base/single_thread_task_runner.h"
|
|
|
|
#include "vendor/node/deps/uv/include/uv.h"
|
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
// TaskRunner implementation that posts tasks into libuv's default loop.
|
|
|
|
class UvTaskRunner : public base::SingleThreadTaskRunner {
|
|
|
|
public:
|
|
|
|
explicit UvTaskRunner(uv_loop_t* loop);
|
|
|
|
|
|
|
|
// base::SingleThreadTaskRunner:
|
2017-12-17 23:56:18 +00:00
|
|
|
bool PostDelayedTask(const base::Location& from_here,
|
2017-06-16 20:39:08 +00:00
|
|
|
base::OnceClosure task,
|
2015-09-03 02:28:50 +00:00
|
|
|
base::TimeDelta delay) override;
|
2017-08-07 21:14:35 +00:00
|
|
|
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:
|
2018-04-17 23:23:40 +00:00
|
|
|
~UvTaskRunner() override;
|
2015-09-03 02:28:50 +00:00
|
|
|
static void OnTimeout(uv_timer_t* timer);
|
2015-10-21 12:46:16 +00:00
|
|
|
static void OnClose(uv_handle_t* handle);
|
2015-09-03 02:28:50 +00:00
|
|
|
|
|
|
|
uv_loop_t* loop_;
|
|
|
|
|
2017-06-16 20:39:08 +00:00
|
|
|
std::map<uv_timer_t*, base::OnceClosure> tasks_;
|
2015-09-03 02:28:50 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(UvTaskRunner);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
#endif // ATOM_APP_UV_TASK_RUNNER_H_
|