File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55#include < iostream>
66#include < thread>
77
8+ namespace {
9+
10+ constexpr auto CounterInterval = std::chrono::seconds{ 1 };
11+ constexpr std::uint64_t CounterLimit = 10 ;
12+ constexpr auto BackgroundTaskRuntime = std::chrono::milliseconds{ 50 };
13+ constexpr int BackgroundStepsPerRun = 3 ;
14+
15+ } // namespace
16+
817int main ()
918{
10- using namespace std ::chrono_literals;
1119 using Clock = std::chrono::steady_clock;
1220
1321 olga_scheduler::EventLoop<Clock> loop;
1422 std::uint64_t counter = 0 ;
1523 std::uint64_t bg_counter = 0 ;
1624
17- auto evt = loop.repeat (1s , [&](const auto & arg) {
25+ auto evt = loop.repeat (CounterInterval , [&](const auto & arg) {
1826 ++counter;
1927 std::cout << " counter=" << counter << " now=" << arg.approx_now .time_since_epoch ().count () << ' \n ' ;
20- if (counter > 10 ) {
28+ if (counter > CounterLimit ) {
2129 arg.event .cancel ();
2230 }
2331 });
2432
2533 auto run_background_step = [&] {
2634 ++bg_counter;
2735 std::cout << " bg_counter=" << bg_counter << ' \n ' ;
28- std::this_thread::sleep_for (50ms );
36+ std::this_thread::sleep_for (BackgroundTaskRuntime );
2937 };
3038
3139 while (!loop.isEmpty ()) {
3240 const auto spin_result = loop.spin ();
3341
3442 if ((counter > 0 ) && !loop.isEmpty ()) {
35- for (int i = 0 ; (i < 3 ) && (Clock::now () < spin_result.next_deadline ); ++i) {
43+ for (int i = 0 ; (i < BackgroundStepsPerRun ) && (Clock::now () < spin_result.next_deadline ); ++i) {
3644 run_background_step ();
3745 }
3846 }
You can’t perform that action at this time.
0 commit comments