Document the behavior of async_stream_nolink #13285
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi!
I spent some time struggling trying to implement something relatively simple with
Task.async_stream
/Task.Supervisor.async_stream_nolink
, did many experiments, until I realized it was due to a misunderstanding and that I could actually solve it simply.In my previous mental model,
Task.Supervisor.async_stream_nolink
meant "fire and forget" without a mean to cleanup dangling tasks if I wanted to bail on the first error. I didn't realize these tasks were cleaned up by an extra monitor when the stream halted, making it perfectly suited for my needs without any need to hack.This PR is an attempt to clarify this behavior in the doc, and leave a couple of recipes which I think can be very useful for daily tasks and understanding.
Another idea could be to simplify this common use case by adding a
bail: true
option. Forasync_stream
, we exit immediately so it is not an issue, but forasync_stream_nolink
it might be useful.