Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle subtasks gracefully #20

Open
kalabukdima opened this issue Oct 22, 2024 · 0 comments
Open

Handle subtasks gracefully #20

kalabukdima opened this issue Oct 22, 2024 · 0 comments

Comments

@kalabukdima
Copy link
Collaborator

There is a common pattern (not only in the worker, but across all our components) which is difficult to describe with safe Rust:

  • multiple subtasks are running concurrently forever
  • if any of them completes (e.g. panics), all the rest should also be terminated
  • the termination has to be graceful — set the cancellation token and wait for the task to end
  • subtasks may want to split themselves into other subtasks.

Basically, it's what is called "structured concurrency"
The main complication is that to run the subtasks truly in parallel you have to use tokio::spawn which accepts a 'static future (scoped tasks have been removed), making you pass all the shared objects wrapped in Arc.

The task_scope crate looks like a possible solution, but it's very unpopular, so it should be carefully reviewed first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant