VoxelEngine/src/util/RunnablesList.hpp
2024-08-10 01:57:59 +03:00

31 lines
689 B
C++

#pragma once
#include <memory>
#include <unordered_map>
#include <utility>
#include "delegates.hpp"
#include "typedefs.hpp"
namespace util {
class RunnablesList {
int nextid = 1;
std::unordered_map<int, runnable> runnables;
public:
observer_handler add(runnable callback) {
int id = nextid++;
runnables[id] = std::move(callback);
return observer_handler(new int(id), [this](int* id) { //-V508
runnables.erase(*id);
delete id;
});
}
void notify() {
for (auto& entry : runnables) {
entry.second();
}
}
};
}