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

Document the behavior of async_stream_nolink #13285

Merged
merged 3 commits into from
Jan 26, 2024

Conversation

sabiwara
Copy link
Contributor

@sabiwara sabiwara commented Jan 26, 2024

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.

Screenshot 2024-01-26 at 9 00 20

Another idea could be to simplify this common use case by adding a bail: true option. For async_stream, we exit immediately so it is not an issue, but for async_stream_nolink it might be useful.

@sabiwara
Copy link
Contributor Author

@whatyouhide Thank you for the suggestions 💜

@sabiwara sabiwara merged commit 2d50a36 into elixir-lang:main Jan 26, 2024
8 checks passed
@sabiwara sabiwara deleted the async_stream_doc branch January 26, 2024 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants