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

Add mechanism for posting functions to the main loop #2082

Merged
merged 2 commits into from
Jun 8, 2016

Conversation

igrr
Copy link
Member

@igrr igrr commented Jun 2, 2016

As mentioned in #1064.
This pull request adds two functions:

bool schedule_function(std::function<void(void)> fn);
May be used to run given function next time loop function returns, or run_scheduled_functions is called. std::bind may be used to pass arguments to a function, or call a class member function.

void run_scheduled_functions();
Runs all scheduled functions. This function may be used if loop is not being used, or it does not return on a regular basis (i.e. there an explicit loop somewhere in setup or in library code).

TODO:

  • return a token object which controls lifetime of the scheduled callback. I.e. if an object schedules a function and then the object gets destroyed, the scheduled function should not be called. May also be used as a mechanism to cancel scheduled functions. (to be addressed in another pull request)
  • fix code formatting

@codecov-io
Copy link

codecov-io commented Jun 2, 2016

Current coverage is 42.59%

Merging #2082 into master will increase coverage by 16.29%

@@             master      #2082   diff @@
==========================================
  Files            19         19          
  Lines          3634       3634          
  Methods         328        328          
  Messages          0          0          
  Branches        585        585          
==========================================
+ Hits            956       1548   +592   
+ Misses         2513       2086   -427   
+ Partials        165          0   -165   

Powered by Codecov. Last updated by 32bd42b...1090c28

@igrr igrr force-pushed the feature/schedule_functions branch from 1090c28 to f4ead4d Compare June 6, 2016 07:19
@igrr igrr force-pushed the feature/schedule_functions branch from f4ead4d to 1d0eb22 Compare June 6, 2016 07:21
@igrr igrr merged commit 5eb6a7f into master Jun 8, 2016
@igrr igrr deleted the feature/schedule_functions branch June 8, 2016 03:28
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

Successfully merging this pull request may close these issues.

2 participants