uv_task_runner.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 ELECTRON_SHELL_APP_UV_TASK_RUNNER_H_
  5. #define ELECTRON_SHELL_APP_UV_TASK_RUNNER_H_
  6. #include <map>
  7. #include "base/memory/raw_ptr.h"
  8. #include "base/task/single_thread_task_runner.h"
  9. #include "shell/common/node_bindings.h"
  10. namespace base {
  11. class Location;
  12. class TimeDelta;
  13. } // namespace base
  14. namespace electron {
  15. // TaskRunner implementation that posts tasks into libuv's default loop.
  16. class UvTaskRunner : public base::SingleThreadTaskRunner {
  17. public:
  18. explicit UvTaskRunner(uv_loop_t* loop);
  19. // disable copy
  20. UvTaskRunner(const UvTaskRunner&) = delete;
  21. UvTaskRunner& operator=(const UvTaskRunner&) = delete;
  22. // base::SingleThreadTaskRunner:
  23. bool PostDelayedTask(const base::Location& from_here,
  24. base::OnceClosure task,
  25. base::TimeDelta delay) override;
  26. bool RunsTasksInCurrentSequence() const override;
  27. bool PostNonNestableDelayedTask(const base::Location& from_here,
  28. base::OnceClosure task,
  29. base::TimeDelta delay) override;
  30. private:
  31. ~UvTaskRunner() override;
  32. raw_ptr<uv_loop_t> loop_;
  33. std::map<UvHandle<uv_timer_t>, base::OnceClosure, UvHandleCompare> tasks_;
  34. };
  35. } // namespace electron
  36. #endif // ELECTRON_SHELL_APP_UV_TASK_RUNNER_H_