From 87de5ca3f401541866e83294e0829e33f2633be0 Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Tue, 6 Jul 2021 12:23:47 +0200 Subject: [PATCH] Use the deferred policy when --parallel isn't present. --- src/main.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e6f84c7..83e85ca 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,10 +28,11 @@ int main(int argc, char* argv[]) { } if (!files.empty()) { const set uniqueFiles(files.begin(), files.end()); - vector> units; + vector> Units; for (string_view fileName: uniqueFiles) { if (fileName != "none") { - future newAsync = async(launch::async, [printResult, fileName, target]() mutable { + const launch Policy = !parallel ? launch::deferred : launch::async; + future newAsync = async(Policy, [printResult, fileName, target]() mutable { const string transpiledString = transpile(parseString(getFileContent(fileName.data())), target); stringstream consoleOutput; if (printResult) consoleOutput << "~~~~[Yerbacon compilation result]~~~~\n\n" << "[WIP]\n" << transpiledString << "\n\n"; @@ -41,14 +42,10 @@ int main(int argc, char* argv[]) { outputFileContent(outputFile, transpiledString); return consoleOutput.str(); }); - if (!parallel) cout << newAsync.get(); else { - units.push_back(move(newAsync)); - } + Units.push_back(move(newAsync)); } } - for (auto& currentThread: units) { - cout << currentThread.get(); - } + for (auto& currentFuture: Units) cout << currentFuture.get(); } else cout << "No valid file provided.\n"; } return EXIT_SUCCESS;