Skip to content

JoinHandle.abort #5534

Answered by Darksonn
itamarsch asked this question in Q&A
Mar 8, 2023 · 3 comments · 4 replies
Discussion options

You must be logged in to vote

The abort method will cancel the task next time it yields at an .await. For tasks that don't block the thread, this means that it will be cancelled immediately.

Cancellation is done by running the destructor of the future, which runs the destructor of all local variables defined inside the future. This also cleans up all memory owned by the future.

Using abort is not bad practice — it works great as long as you don't need to do any asynchronous cleanup. For cases where abort is not sufficient, you can use the techniques outlined in the page on graceful shutdown on the Tokio website.

It certainly does not cause UB. Like the standard library, Tokio promises that causing UB with only safe co…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@itamarsch
Comment options

@ShaneMurphy2
Comment options

@Darksonn
Comment options

@ShaneMurphy2
Comment options

Answer selected by itamarsch
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants