mirror of https://gitlab.com/cppit/jucipp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
591 B
30 lines
591 B
#include "dispatcher.h" |
|
|
|
Dispatcher::Dispatcher() { |
|
connection=dispatcher.connect([this] { |
|
functions_mutex.lock(); |
|
for(auto &function: functions) { |
|
function(); |
|
} |
|
functions.clear(); |
|
functions_mutex.unlock(); |
|
}); |
|
} |
|
|
|
Dispatcher::~Dispatcher() { |
|
disconnect(); |
|
functions_mutex.lock(); |
|
functions.clear(); |
|
functions_mutex.unlock(); |
|
} |
|
|
|
void Dispatcher::add(std::function<void()> function) { |
|
functions_mutex.lock(); |
|
functions.emplace_back(function); |
|
functions_mutex.unlock(); |
|
dispatcher(); |
|
} |
|
|
|
void Dispatcher::disconnect() { |
|
connection.disconnect(); |
|
}
|
|
|