Have the channel hold a slice of objects and process them as a batch. Batch in - batch out.
Typically unless your traffic is bursty - a faster producer than consumer will either cause blocking, data loss (drops) or failure (oom). > On Apr 13, 2021, at 8:00 AM, Roman Leventov <leventov...@gmail.com> wrote: > > > Jesper, a single channel works if I provision it with big enough capacity > (1000), but this feels like an antipattern which can break. Still, this is > probably the most practical option. > > Brian, thanks for sharing, yes this pattern solves my problem much simpler > than I have. Although it doesn't feel right that achieving something that > feels like basic concurrent programming turns into Koan solving. > >> On Tue, 13 Apr 2021 at 14:43, Brian Candler <b.cand...@pobox.com> wrote: >> Bryan Mill's presentation on go concurrency patterns is well worth watching >> all the way through: >> https://www.youtube.com/watch?v=5zXAHh5tJqQ >> >> There are lots of code snippets which are directly relevant to what you're >> trying to do, e.g. from 20:48 is a queue with Get, and 21:59 a queue with >> GetMany. He starts with the traditional semaphore approach and then shows a >> much cleaner and simpler way of doing it. >> >> The biggest revelation I got was: instead of having a data structure >> protected by a mutex, you can stuff a data structure into a one-element >> buffered channel. When you need to use it: pop it out, modify it, push it >> back in. Very easy to reason about. >> -- >> You received this message because you are subscribed to a topic in the >> Google Groups "golang-nuts" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/golang-nuts/bNF_KXUiKHs/unsubscribe. >> To unsubscribe from this group and all its topics, send an email to >> golang-nuts+unsubscr...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/golang-nuts/7b198a7b-daaf-435b-930f-bb318dd838e3n%40googlegroups.com. > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/CAAMLo%3DYqkBjgz7tL13GE9_hetP79JG-q-PW5ze6UmXVE%3DYU%3DQQ%40mail.gmail.com. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/9FDCE76E-68C6-4F70-ACAA-A53E9FC4ED19%40ix.netcom.com.