mirror of
https://github.com/Syping/dtranslatebot.git
synced 2026-04-21 14:40:41 +02:00
{message,submit}_queue: add size() function and callback
This commit is contained in:
parent
f25b1ac4db
commit
2d96e35793
4 changed files with 51 additions and 3 deletions
|
|
@ -101,6 +101,8 @@ void message_queue::run(bot::settings::settings *settings, submit_queue *submit_
|
|||
if (!m_queue.empty()) {
|
||||
const message message = m_queue.front();
|
||||
m_queue.pop();
|
||||
for (message_queue_size_callback &callback : m_callbacks)
|
||||
callback(m_queue.size());
|
||||
m_mutex.unlock();
|
||||
|
||||
auto translator = settings->get_translator();
|
||||
|
|
@ -134,6 +136,23 @@ void message_queue::run(bot::settings::settings *settings, submit_queue *submit_
|
|||
}
|
||||
}
|
||||
|
||||
size_t message_queue::size() {
|
||||
const std::lock_guard<std::mutex> guard(m_mutex);
|
||||
return m_queue.size();
|
||||
}
|
||||
|
||||
void message_queue::size_callback_add(const message_queue_size_callback &callback) {
|
||||
const std::lock_guard<std::mutex> guard(m_mutex);
|
||||
m_callbacks.push_back(callback);
|
||||
}
|
||||
|
||||
/*
|
||||
void message_queue::size_callback_remove(const message_queue_size_callback &callback) {
|
||||
const std::lock_guard<std::mutex> guard(m_mutex);
|
||||
m_callbacks.erase(std::remove(m_callbacks.begin(), m_callbacks.end(), callback));
|
||||
}
|
||||
*/
|
||||
|
||||
void message_queue::terminate()
|
||||
{
|
||||
m_running = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue