1//! @file action.cpp
2//! @author ryftchen
3//! @brief The definitions (action) in the application module.
4//! @version 0.1.0
5//! @copyright Copyright (c) 2022-2025 ryftchen. All rights reserved.
6
7#include "action.hpp"
8
9namespace application::action
10{
11std::atomic_bool Awaitable::active = false;
12
13Awaitable::Awaitable(const std::coroutine_handle<promise_type>& handle) : handle{handle}
14{
15 if (active.load())
16 {
17 throw std::runtime_error{"There can only be one awaitable instance active at any given time."};
18 }
19 active.store(i: true);
20}
21
22Awaitable::~Awaitable()
23{
24 active.store(i: false);
25 if (handle)
26 {
27 handle.destroy();
28 }
29}
30
31void Awaitable::resume() const
32{
33 if (handle)
34 {
35 handle.resume();
36 }
37}
38
39bool Awaitable::done() const
40{
41 return !handle || handle.done();
42}
43} // namespace application::action
44