Skip to content

integration of run_loop with other event loops #172

Open
@ericniebler

Description

@ericniebler

The run member function of run_loop consumes the current thread until the run loop finishes. There should be a way to tell the run_loop to delegate execution to a separate event loop, like a system event loop.

I can imagine users calling run_loop::run with an optional callable, which run will call periodically; maybe after every item that run processes.

void run_loop::run( callable auto fn ) {
  while( auto item = pop_front() ) {
    item.execute();
    if( !fn( [this]() -> bool { return !this->_is_empty(); } ) )
      break;
    }
  }
}

run invokes the callable with a predicate that indicates whether the run loop's queue is empty or not. We can use this to drive two run_loops on the same thread:

run_loop loop1, loop2;


loop1.run(
  [&](auto has_work) {
    // Run loop2 while loop1 is empty
    loop2.run( [&](auto) { return has_work(); } );
  }
);

Metadata

Metadata

Labels

discussionWe need to talk about this; there's nothing actionable here yetenhancementNew feature or requestneeds-paperNeeds a paper to be writtensystem-schedulerTasks relating to the system-scheduler / thread-pooltokyoIssues to be worked on in Tokyo 2024 workshop

Type

No type

Projects

Status

Ready

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions