Re: [go-nuts] Re: how to implement channel priorities?

2019-05-24 Thread Bruno Albuquerque
This is what my solution does, except that it uses items associated with priorities instead of 2 channels. if 2 channels are really needed for some reason, it is easy to adapt the solution to this. On Fri, May 24, 2019 at 12:12 PM Daniela Petruzalek < daniela.petruza...@gmail.com> wrote: > If I

Re: [go-nuts] Re: how to implement channel priorities?

2019-05-24 Thread Daniela Petruzalek
If I had to process messages from both high and low priority channels I would serialise then with a min heap and create a consumer process for the min heap. The min heap seems to be the canonical way of solving the priority queues anyway, so I think it makes sense here. Basically: goroutine 1

Re: [go-nuts] Re: how to implement channel priorities?

2019-05-24 Thread Michael Jones
I see an easy* way to implement channel priorities in Go2 if that is desired. two steps: step 2: At lines 124 and 153-157 of src/runtime/select.go, an *order of channel testing* index table is created, then permuted. It is later visited in order. All that needs doing is to make the index table

Re: [go-nuts] Re: how to implement channel priorities?

2019-05-24 Thread Bruno Albuquerque
On Fri, May 24, 2019 at 1:50 AM roger peppe wrote: > On Thu, 23 May 2019 at 19:28, Bruno Albuquerque wrote: > >> This was my attempt at a channel with priorities: >> >> >> https://git.bug-br.org.br/bga/channels/src/master/priority/channel_adapter.go >> >> Based on the assumption that priorities

Re: [go-nuts] Re: how to implement channel priorities?

2019-05-24 Thread Bruno Albuquerque
On Fri, May 24, 2019 at 8:40 AM roger peppe wrote: > On Fri, 24 May 2019 at 16:25, Bruno Albuquerque wrote: > >> On Fri, May 24, 2019 at 1:50 AM roger peppe wrote: >> >>> On Thu, 23 May 2019 at 19:28, Bruno Albuquerque wrote: >>> This was my attempt at a channel with priorities:

Re: [go-nuts] Re: how to implement channel priorities?

2019-05-24 Thread roger peppe
On Fri, 24 May 2019 at 16:25, Bruno Albuquerque wrote: > On Fri, May 24, 2019 at 1:50 AM roger peppe wrote: > >> On Thu, 23 May 2019 at 19:28, Bruno Albuquerque wrote: >> >>> This was my attempt at a channel with priorities: >>> >>> >>>

Re: [go-nuts] Re: how to implement channel priorities?

2019-05-24 Thread roger peppe
On Thu, 23 May 2019 at 19:28, Bruno Albuquerque wrote: > This was my attempt at a channel with priorities: > > > https://git.bug-br.org.br/bga/channels/src/master/priority/channel_adapter.go > > Based on the assumption that priorities only make sense if items are > queued. If they are pulled out

Re: [go-nuts] Re: how to implement channel priorities?

2019-05-23 Thread Anthony Metzidis
Good point i'll update with a timeout to flush in case traffic is slow On Thu, May 23, 2019 at 1:38 AM roger peppe wrote: > On Thu, 23 May 2019 at 01:34, Anthony Metzidis > wrote: > >> Fun thought exercise -- here's another approach. >> >> >> https://play.golang.org/p/Xu7iWhY4PUQ >> > > ISTM

Re: [go-nuts] Re: how to implement channel priorities?

2019-05-23 Thread Bruno Albuquerque
This was my attempt at a channel with priorities: https://git.bug-br.org.br/bga/channels/src/master/priority/channel_adapter.go Based on the assumption that priorities only make sense if items are queued. If they are pulled out from a channel as fast as they are added to it, then there is no

Re: [go-nuts] Re: how to implement channel priorities?

2019-05-23 Thread roger peppe
Oops, forgot to include the playground link at the end there: https://play.golang.org/p/mYSRsGb4mRA On Thu, 23 May 2019 at 09:38, roger peppe wrote: > On Thu, 23 May 2019 at 01:34, Anthony Metzidis > wrote: > >> Fun thought exercise -- here's another approach. >> >> >>

Re: [go-nuts] Re: how to implement channel priorities?

2019-05-23 Thread roger peppe
On Thu, 23 May 2019 at 01:34, Anthony Metzidis wrote: > Fun thought exercise -- here's another approach. > > > https://play.golang.org/p/Xu7iWhY4PUQ > ISTM that that approach doesn't work because you're buffering 10 values before you send any. So if you have a situation when you've got very

Re: [go-nuts] Re: how to implement channel priorities?

2019-05-22 Thread Anthony Metzidis
Fun thought exercise -- here's another approach. https://play.golang.org/p/Xu7iWhY4PUQ package main import ( "fmt" "math/rand" "sort" "time" "strconv" ) type PriorityStruct struct { Pint name string } const BUFSIZE = 10 type PriorityChan chan PriorityStruct type PriorityBuf

[go-nuts] Re: how to implement channel priorities?

2019-05-21 Thread jterry via golang-nuts
Would this work? select { case val := <-high: continue default: } select { case val := <-high: case val := <-high: case val := <-high: case val := <-low: } On Monday, July 23, 2012 at 2:16:16 PM UTC-7, Erwin wrote: > > Hello, > > i wonder how to implement channel priorities nicely. Say there

[go-nuts] Re: how to implement channel priorities?

2019-02-14 Thread kanglingv
select { case highVal := <- high: case lowVal := <- low: if len(high) > 0 { for len(high) > 0 { highVal := <- high } } // process lowVal } On Tuesday, July 24, 2012 at 5:16:16 AM UTC+8, Erwin Driessens wrote: > > Hello, > >