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

Directly kill task without waiting for finish #1038

Open
DasLixou opened this issue Sep 25, 2022 · 2 comments
Open

Directly kill task without waiting for finish #1038

DasLixou opened this issue Sep 25, 2022 · 2 comments

Comments

@DasLixou
Copy link

hi im new to rust and stumbled across this library. currently i try to do a simple music application and have a music player running inside a task. but the problem is that i now cant directly stop the task. i tried it with JoinHandler.cancel().await but that just waits till the task is finished. is there a way to directly kill it? thanks :D

@notgull
Copy link
Contributor

notgull commented Sep 25, 2022

cancel() waits for the task to reappear in the executor's queue for the last time before it dies. For async tasks, this should be instant. However, if it isn't instant, what I'd suspect is that your task contains a blocking call.

@ZhennanWu
Copy link

ZhennanWu commented Nov 13, 2022

I agree with the poster that async-std is missing this capability. tokio has a synchronous JoinHandle::abort and smol has the equivalent synchronous cancel-on-drop. async-std currently has absolutely no way of synchronously cancel a task. This is unfortunate since the underlying smol already has a readily available Task::set_canceled(&mut self).

The only thing left is just to introduce a new method JoinHandle::whatever_name_for_sync_cancel(self).

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

3 participants