Use symmetric spawn-then-run() pattern in multi-task examples

Switch every example to ``await runner.spawn(task)`` followed by
``await runner.run()`` (no task argument), and ``await runner.cancel()``
on client-disconnected instead of ``await task.cancel()``. This makes
the main pipeline task look the same as the worker / proxy tasks
spawned alongside it, and lets ``runner.cancel()`` drive a uniform
shutdown across every root task on the bus.
This commit is contained in:
Aleix Conchillo Flaqué
2026-05-15 08:46:46 -07:00
parent 5f1b91bb89
commit f22350ce2f
6 changed files with 31 additions and 25 deletions

View File

@@ -145,8 +145,6 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
idle_timeout_secs=runner_args.pipeline_idle_timeout_secs,
)
await runner.spawn(CodeWorker("code_worker", project_path=PROJECT_PATH))
@transport.event_handler("on_client_connected")
async def on_client_connected(transport, client):
logger.info("Client connected")
@@ -161,9 +159,12 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
@transport.event_handler("on_client_disconnected")
async def on_client_disconnected(transport, client):
logger.info("Client disconnected")
await task.cancel()
await runner.cancel()
await runner.run(task)
await runner.spawn(CodeWorker("code_worker", project_path=PROJECT_PATH))
await runner.spawn(task)
await runner.run()
async def bot(runner_args: RunnerArguments):