3 ms·
x/sync is great. I use things like singlelfight frequently. > Generally this is consumers closing channels, which is not a good idea. I've heard this too. I u
by parhamn 2y ago
x/sync is great. I use things like singlelfight frequently.
> Generally this is consumers closing channels, which is not a good idea.
I've heard this too. I updated my comment to include the code snippet. But any general tips on when the consumer needs to cancel the rest of the work because of an error?
I don't recall now but I think I ended up writing my own for fast-fail and generic support. Really hoping the x/sync packages get generic support soon!
> a 1-message channel is practical
Great tip, every time I add a little signal one I feel like I did something wrong, maybe that is the move.
- jerf 2y ago"But any general tips on when the consumer needs to cancel the rest of the work because of an error?" Yes, another channel which everyone watches for cancellation. In modern Go, that should be a context and it's .Done() channel. This is another "I'm not saying you suck because I did this myself a while before I figured it out", but having a channel around just to cancel things is fine. It doesn't cost anything significantly extra. I have some still in my code bases where I've just never had any reason to upgrade to contexts.
- deleted 2y ago[deleted]