async: context: simplify run function
Since we already have a `spawn` function to add async tasks,
get rid of the special "startup" task send to run. Instead
users should pass the start up work to spawn and call run with
no parameters.
Eventually this will allow us to exit the run-loop for any and all
exceptions from the async context and potentially allow a caller
to re-enter the `run` loop after handling the child exception.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ia0e09a2493f0554538315d1d0c238aa11cb44e39
diff --git a/src/async/context.cpp b/src/async/context.cpp
index 4807a6a..36f5552 100644
--- a/src/async/context.cpp
+++ b/src/async/context.cpp
@@ -148,12 +148,10 @@
return first_stop;
}
-void context::caller_run(task<> startup)
+void context::run()
{
// Start up the worker thread.
- worker_thread = std::thread{[this, startup = std::move(startup)]() mutable {
- worker_run(std::move(startup));
- }};
+ worker_thread = std::thread{[this]() { worker_run(); }};
// Run until the context requested to stop.
while (!final_stop.stop_requested())
@@ -184,15 +182,9 @@
}
}
-void context::worker_run(task<> startup)
+void context::worker_run()
{
- // Begin the 'startup' task.
- // This shouldn't start detached because we want to be able to forward
- // failures back to the 'run'. execution::ensure_started isn't
- // implemented yet, so we don't have a lot of other options.
- spawn(std::move(startup));
-
- // Also start the sdbus 'wait/process' loop; treat it as an internal task.
+ // Start the sdbus 'wait/process' loop; treat it as an internal task.
internal_tasks.spawn(details::wait_process_completion::loop(*this));
// Run the execution::run_loop to handle all the tasks.