Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/xaliphostes/task


https://github.com/xaliphostes/task

Last synced: 19 days ago
JSON representation

Awesome Lists containing this project

README

        

# Task


Linux support
macOS support
Windows support


Language
License

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
#include

class 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]