Load autoloaded automation scripts in parallel
This commit is contained in:
parent
a75b7f6ca8
commit
df73591a54
1 changed files with 14 additions and 7 deletions
|
@ -56,6 +56,7 @@
|
||||||
#include <boost/algorithm/string/trim.hpp>
|
#include <boost/algorithm/string/trim.hpp>
|
||||||
#include <boost/format.hpp>
|
#include <boost/format.hpp>
|
||||||
#include <boost/tokenizer.hpp>
|
#include <boost/tokenizer.hpp>
|
||||||
|
#include <future>
|
||||||
|
|
||||||
#include <wx/dcmemory.h>
|
#include <wx/dcmemory.h>
|
||||||
#include <wx/log.h>
|
#include <wx/log.h>
|
||||||
|
@ -340,21 +341,27 @@ namespace Automation4 {
|
||||||
{
|
{
|
||||||
scripts.clear();
|
scripts.clear();
|
||||||
|
|
||||||
int error_count = 0;
|
std::vector<std::future<std::unique_ptr<Script>>> script_futures;
|
||||||
|
|
||||||
boost::char_separator<char> sep("|");
|
boost::char_separator<char> sep("|");
|
||||||
for (auto const& tok : boost::tokenizer<boost::char_separator<char>>(path, sep)) {
|
for (auto const& tok : boost::tokenizer<boost::char_separator<char>>(path, sep)) {
|
||||||
auto dirname = config::path->Decode(tok);
|
auto dirname = config::path->Decode(tok);
|
||||||
if (!agi::fs::DirectoryExists(dirname)) continue;
|
if (!agi::fs::DirectoryExists(dirname)) continue;
|
||||||
|
|
||||||
for (auto filename : agi::fs::DirectoryIterator(dirname, "*.*")) {
|
for (auto filename : agi::fs::DirectoryIterator(dirname, "*.*"))
|
||||||
auto s = ScriptFactory::CreateFromFile(dirname/filename, false, false);
|
script_futures.emplace_back(std::async(std::launch::async, [=] {
|
||||||
|
return ScriptFactory::CreateFromFile(dirname/filename, false, false);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
int error_count = 0;
|
||||||
|
for (auto& future : script_futures) {
|
||||||
|
auto s = future.get();
|
||||||
if (s) {
|
if (s) {
|
||||||
if (!s->GetLoadedState()) ++error_count;
|
if (!s->GetLoadedState()) ++error_count;
|
||||||
scripts.emplace_back(std::move(s));
|
scripts.emplace_back(std::move(s));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (error_count == 1) {
|
if (error_count == 1) {
|
||||||
wxLogWarning("A script in the Automation autoload directory failed to load.\nPlease review the errors, fix them and use the Rescan Autoload Dir button in Automation Manager to load the scripts again.");
|
wxLogWarning("A script in the Automation autoload directory failed to load.\nPlease review the errors, fix them and use the Rescan Autoload Dir button in Automation Manager to load the scripts again.");
|
||||||
|
|
Loading…
Reference in a new issue