diff --git a/src/main.cpp b/src/main.cpp index 5bc653d..e6f84c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,8 @@ #include #include #include +#include +#include using namespace std; #include "headers/misc.hpp" @@ -26,24 +28,26 @@ int main(int argc, char* argv[]) { } if (!files.empty()) { const set uniqueFiles(files.begin(), files.end()); - vector threads; + vector> units; for (string_view fileName: uniqueFiles) { if (fileName != "none") { - thread newThread = thread([printResult, fileName, target]() mutable { + future newAsync = async(launch::async, [printResult, fileName, target]() mutable { const string transpiledString = transpile(parseString(getFileContent(fileName.data())), target); - if (printResult) cout << "~~~~[Yerbacon compilation result]~~~~\n\n" << "[WIP]\n" << transpiledString << "\n\n"; + stringstream consoleOutput; + if (printResult) consoleOutput << "~~~~[Yerbacon compilation result]~~~~\n\n" << "[WIP]\n" << transpiledString << "\n\n"; fileName.remove_suffix(6); string outputFile; (outputFile = fileName).append(target); outputFileContent(outputFile, transpiledString); + return consoleOutput.str(); }); - if (!parallel) newThread.join(); else { - threads.push_back(move(newThread)); + if (!parallel) cout << newAsync.get(); else { + units.push_back(move(newAsync)); } } } - for (auto& currentThread: threads) { - currentThread.join(); + for (auto& currentThread: units) { + cout << currentThread.get(); } } else cout << "No valid file provided.\n"; }