Yes, unless you have a specific reason not to.
Russ
i wonder if there's room in the standard library for
an unlimited size queue where readers block
if the queue is empty (a slightly harder problem
than the original above).
something like that described by the following interface:
type Q interface {
Put(x interface{})
Get() interface{}
Close()
Closed() bool
}
it's not often what you need, but when you do need
it, it's useful to avoid implementing it again.
This seems trivial to implement in my mind, a single goroutine
maintaining a vector of data that does a select{} (if theres data to
send) on an input and output channel, input received goes into the
vector, output goes out on request.
it's trivial but not *that* trivial.
and it would be nice if it could avoid the extra goroutine,
so they could be garbage collected as easily as buffered channels.
I'm having trouble implementing just this. Do you have an implementation you'd be willing to share? I'd like to have both a blocking and non-blocking dequeue method.
On Wednesday, October 20, 2010 2:20:57 PM UTC-4, Corey Thomasson wrote:On 20 October 2010 14:14, roger peppe <rogp...@gmail.com> wrote:
> On 20 October 2010 18:34, Russ Cox <r...@golang.org> wrote:
>>> Or do you simply use channels themselves as the queue?
>>
>> Yes, unless you have a specific reason not to.
>
> i wonder if there's room in the standard library for
> an unlimited size queue where readers block
> if the queue is empty (a slightly harder problem
> than the original above).This seems trivial to implement in my mind, a single goroutine
maintaining a vector of data that does a select{} (if theres data to
send) on an input and output channel, input received goes into the
vector, output goes out on request.> something like that described by the following interface:
>
> type Q interface {
> Put(x interface{})
> Get() interface{}
> Close()
> Closed() bool
> }
>
> it's not often what you need, but when you do need
> it, it's useful to avoid implementing it again.
>
--
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...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.