Skip to content

Instantly share code, notes, and snippets.

@Naios
Created June 20, 2016 18:34
Show Gist options
  • Save Naios/3facf9004bd5ea0eda95cb4cc3e9d983 to your computer and use it in GitHub Desktop.
Save Naios/3facf9004bd5ea0eda95cb4cc3e9d983 to your computer and use it in GitHub Desktop.
#include "TaskScheduler.h"
#include "Duration.h"
template<typename T, typename P>
std::function<void(TaskContext)> ExecuteWhen(T&& task, P&& predicate) {
return [=](TaskContext context) {
if (predicate())
task(std::move(context));
else
context.Repeat(Milliseconds(10));
};
}
void test()
{
TaskScheduler scheduler;
auto task = [](TaskContext) { /*...*/ };
auto predicate = [] { return true /*...*/; };
scheduler.Schedule(Seconds(5), ExecuteWhen(task, predicate));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment