Bosma / Scheduler

Modern C++ Scheduling Library
MIT License
273 stars 75 forks source link

Initialize scheduler in class #20

Open njoye opened 5 years ago

njoye commented 5 years ago

Similar to #11 I'd like to use the scheduler inside a method of another class. Say I have Class A and Class B where A calls b.schedule() (and b is an instance of Class B), with the following code:

public: void schedule(){ Bosma::Scheduler s(12); s.every(std::chrono::milliseconds(100), [](){ // Do something in here } }

In my case, this will execute the code inside the lambda function only once. I already tried getting around this by initializing the Scheduler in-class, like this:

class ClassA(){ public: Bosma::Scheduler s(12); }

but like that compilation fails and states expected identifier before numeric constant. I also tried other variants of initialization, but since the scheduler object can't be moved or copied, these do not work either.

In the end, I just want to be able to have a modular system, where I do not expose the scheduling to the calling class / function. Is that possible, and if so: how ?