- if chan cap <= C (say 16), allocate it eagerly as now.
- then double allocation on overflow until max capacity.
items, but that bound isn't known when the channel is created? InWhat if you have an agent that is known to produce a bounded number of
addition, suppose that this agent doesn't care whether there is anyone
receiving from the channel or how quickly. It has some limited amount
of work to do, the output should be sent to a channel without
blocking, and then the agent should exit. If there is no other agent
receiving, then the channel and all buffered items should be garbage
collected.
I've run into this pattern a few times and couldn't use channels as
the solution precisely because I couldn't guarantee the sender's
ability to finish its work. My IMAP package is one example. I
originally wanted to use channels for delivering command responses,
but since the user may have no interest in the responses to a
particular command (the command was executed for its side-effects, yet
the responses still have to go somewhere), I had to use a slice/append
implementation instead.
ch := make(chan []Result, 1) // the exact cap is not important, as long as the channel is buffered.in your producer() (the only sender of ch), do something like this:// assume ret is the Result you want to send into the channelselect {case ch <- []Result{ret}: // okcase old := <- ch:ch <- append(old, ret)}i think one could guarantee that the select won't block and it will emulatea channel with unbounded capacity (in the one sender case).your consumer just need to do another range over the value received fromthe channel.
The language already allocates all over the place.
The "allocations panicing at runtime breaks compatibility" argument isn't a great one.
--
---
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
The language already allocates all over the place.
The "allocations panicing at runtime breaks compatibility" argument isn't a great one.
Does "i := 0" allocate?