Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xaliphostes/task
https://github.com/xaliphostes/task
Last synced: 19 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/xaliphostes/task
- Owner: xaliphostes
- License: mit
- Created: 2024-11-23T10:44:26.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2024-11-23T10:52:19.000Z (about 1 month ago)
- Last Synced: 2024-11-23T11:27:41.419Z (about 1 month ago)
- Language: C++
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Task
Minimalist Reactive library in C++
## Requirements
- C++20 (but C++23 soon)
- cmake# Compilation
Create a `build` directory, **go inside** and type
```sh
cmake .. && make -j12
```# Running unit tests
**NOTE**: The internal cmake test is used to perform unit testing.In the **same directory** as for the compilation (i.e., the `build` directory), only type
```sh
ctest
```
or
```sh
make test
```# Example for an algorithm
```cpp
#include
#includeclass ExampleAlgorithm : public Algorithm {
public:
void exec(const Args& args = {}) override {
emit("log", Args{std::string("Starting algorithm execution")});
// Simulating a long run
for (int i = 0; i < 100; ++i) {
if (stopRequested()) {
emit("log", Args{std::string("Algorithm stopped by user")});
return;
}// Do something long...
std::this_thread::sleep_for(std::chrono::milliseconds(100));
emit("log", Args{
std::string("Processing: ") + std::to_string(i) + "%"
});
}
emit("log", Args{std::string("Algorithm completed")});
}
};int main() {
ExampleAlgorithm algo;
// Connecting the signals
algo.connect("started", [](const Args& args) {
std::cout << "Algorithm started" << std::endl;
});algo.connect("finished", [](const Args& args) {
std::cout << "Algorithm finished" << std::endl;
});algo.connect("log", [](const Args& args) {
if (!args.empty()) {
try {
std::cout << std::any_cast(args[0]) << std::endl;
} catch (const std::bad_any_cast&) {
std::cout << "Invalid log format" << std::endl;
}
}
});// Run the algo asynchronously
auto future = algo.run();// Possibility to stop the algorithm
std::this_thread::sleep_for(std::chrono::seconds(2));
algo.stop();// Waiting for the algo to end
future.wait();
}
```## Licence
MIT## Contact
[email protected]