uv_task_runner.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright (c) 2015 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ATOM_APP_UV_TASK_RUNNER_H_
  5. #define ATOM_APP_UV_TASK_RUNNER_H_
  6. #include <map>
  7. #include "base/callback.h"
  8. #include "base/single_thread_task_runner.h"
  9. #include "vendor/node/deps/uv/include/uv.h"
  10. namespace atom {
  11. // TaskRunner implementation that posts tasks into libuv's default loop.
  12. class UvTaskRunner : public base::SingleThreadTaskRunner {
  13. public:
  14. explicit UvTaskRunner(uv_loop_t* loop);
  15. ~UvTaskRunner() override;
  16. // base::SingleThreadTaskRunner:
  17. bool PostDelayedTask(const tracked_objects::Location& from_here,
  18. const base::Closure& task,
  19. base::TimeDelta delay) override;
  20. bool RunsTasksOnCurrentThread() const override;
  21. bool PostNonNestableDelayedTask(
  22. const tracked_objects::Location& from_here,
  23. const base::Closure& task,
  24. base::TimeDelta delay) override;
  25. private:
  26. static void OnTimeout(uv_timer_t* timer);
  27. static void OnClose(uv_handle_t* handle);
  28. uv_loop_t* loop_;
  29. std::map<uv_timer_t*, base::Closure> tasks_;
  30. DISALLOW_COPY_AND_ASSIGN(UvTaskRunner);
  31. };
  32. } // namespace atom
  33. #endif // ATOM_APP_UV_TASK_RUNNER_H_