TaskQueue.h 789 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Queue.h>
  8. #include <LibWeb/HTML/EventLoop/Task.h>
  9. namespace Web::HTML {
  10. class TaskQueue {
  11. public:
  12. explicit TaskQueue(HTML::EventLoop&);
  13. ~TaskQueue();
  14. bool is_empty() const { return m_tasks.is_empty(); }
  15. bool has_runnable_tasks() const;
  16. void add(NonnullOwnPtr<HTML::Task>);
  17. OwnPtr<HTML::Task> take_first_runnable();
  18. void enqueue(NonnullOwnPtr<HTML::Task> task) { add(move(task)); }
  19. OwnPtr<HTML::Task> dequeue()
  20. {
  21. if (m_tasks.is_empty())
  22. return {};
  23. return m_tasks.take_first();
  24. }
  25. private:
  26. HTML::EventLoop& m_event_loop;
  27. Vector<NonnullOwnPtr<HTML::Task>> m_tasks;
  28. };
  29. }