diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2023-05-29 06:29:39 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-29 06:29:39 +0000 |
commit | 3fbc71e369fedddd7ebc2eb08c9721860ae6b597 (patch) | |
tree | 297c9e2d905b0ba33978be5f64b9624773661a30 /src/discord/waiter.hpp | |
parent | 8e9fb27e0bec4c9dd4b706e15987cbb16cf42005 (diff) | |
parent | 7da37a2fa90cebf43631c74aa1abfb9842502291 (diff) | |
download | abaddon-portaudio-3fbc71e369fedddd7ebc2eb08c9721860ae6b597.tar.gz abaddon-portaudio-3fbc71e369fedddd7ebc2eb08c9721860ae6b597.zip |
Merge pull request #105 from uowuo/voice
Voice support 🤯
Diffstat (limited to 'src/discord/waiter.hpp')
-rw-r--r-- | src/discord/waiter.hpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/discord/waiter.hpp b/src/discord/waiter.hpp new file mode 100644 index 0000000..0d5ae92 --- /dev/null +++ b/src/discord/waiter.hpp @@ -0,0 +1,29 @@ +#pragma once +#include <chrono> +#include <condition_variable> +#include <mutex> + +class Waiter { +public: + template<class R, class P> + bool wait_for(std::chrono::duration<R, P> const &time) const { + std::unique_lock<std::mutex> lock(m); + return !cv.wait_for(lock, time, [&] { return terminate; }); + } + + void kill() { + std::unique_lock<std::mutex> lock(m); + terminate = true; + cv.notify_all(); + } + + void revive() { + std::unique_lock<std::mutex> lock(m); + terminate = false; + } + +private: + mutable std::condition_variable cv; + mutable std::mutex m; + bool terminate = false; +}; |