Bosma / Scheduler

Modern C++ Scheduling Library
MIT License
272 stars 74 forks source link

call bosma schedulter function from inside function!! #11

Closed bnadem closed 6 years ago

bnadem commented 6 years ago

i want to call function from inside function in class, but dont working! working only on main ! note:scheduling object is inside from member functio of class

Bosma commented 6 years ago

Please provide an example of what you are trying to do.

bnadem commented 6 years ago

i mean inside file :main.cpp classA objectA //call function objectA.functionC(); and in file ClassA implentation cpp file file ClassA.cpp .ClassA::functionA (){ //implementation } ClassA::functionB (){ //implementation } ClassA::functionC (){ unsigned int max_n_threads = 12; Bosma::Scheduler s(max_n_threads); /*!!!!! dont working !!!!!!/ s.in(std::chrono::seconds(1), []() { std::cout << "in one seconcde" << std::endl; });

/*!!!!! dont working !!!!!!/ s.interval(std::chrono::seconds(1), [this]() { this->functionB(); std::this_thread::sleep_for(std::chrono::seconds(5)); }); }

bnadem commented 6 years ago

i mean bosm::scheduler as local variable inside function

Bosma commented 6 years ago

Your example is very poorly done. Please read over what you write and edit it next time. Your comments aren't valid C++, and your attempted lambda functions aren't valid C++. You may need to pick up a tutorial or a textbook, and I recommend going over anything you write (including the spelling of words) and ensuring it is all correct.

Here is how you can do what you are trying to do:

s.interval(std::chrono::seconds(6), [this]() {
  functionB();
});

By the way, sleeping for 5 seconds after the function call with a 1 second interval is the same thing as a 6 second interval, see example.cpp for an explanation.

Alternatively, you can use this syntax: s.interval(std::chrono::seconds(6), &ClassA::functionB, this) I recommend this way.