Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

call bosma schedulter function from inside function!! #11

Closed
bnadem opened this issue May 23, 2018 · 4 comments
Closed

call bosma schedulter function from inside function!! #11

bnadem opened this issue May 23, 2018 · 4 comments

Comments

@bnadem
Copy link

bnadem commented May 23, 2018

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
Copy link
Owner

Bosma commented May 23, 2018

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

@bnadem
Copy link
Author

bnadem commented May 24, 2018

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
Copy link
Author

bnadem commented May 24, 2018

i mean bosm::scheduler as local variable inside function

@Bosma
Copy link
Owner

Bosma commented Jun 3, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants