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

Use tokio::spawn_blocking whenever we perform blocking steps #1579

Open
RolandSherwin opened this issue Apr 8, 2024 · 0 comments
Open

Use tokio::spawn_blocking whenever we perform blocking steps #1579

RolandSherwin opened this issue Apr 8, 2024 · 0 comments

Comments

@RolandSherwin
Copy link
Member

We should be using tokio::spawn_blocking instead of tokio::spawn whenever we are doing sync long running processing inside a task. As this might block the current tokio's worker thread, and will not allow other tasks to progress.

spawn_blocking will use its own thread pool with individual system thread for each task. https://docs.rs/tokio/latest/tokio/task/fn.spawn_blocking.html

We can also use tokio::fs whenever we are doing fs operations? This would automatically upgrade the task to run in its own thread.

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