It seems that you are fighting the helpful infrastructure, but I can’t be sure 
from what you’ve said.

 

You can (presumably) just do this:

 

For u := range streamOfUrls {

 For w := range availableWorkers {

   w.url = u

   activeWorkers <- w

 }

}

 

…but that is strange to me. Why not just have every worker loop for urls on its 
input channel:

 

for I := 0; I < workers; i++ {

    go Worker(urlChannel)

}

 

:

func Worker (uChan chan url) {

for u:= range uChan {

   do work with u

}

}

 

:

for ...range of urls… {

  urlChan <- nextUrl

}

close(urlChan) // will terminate all workers after their last task is assigned

 

From: <golang-nuts@googlegroups.com> on behalf of 
<omarshariffdontlik...@gmail.com>
Date: Wednesday, November 30, 2016 at 9:07 AM
To: golang-nuts <golang-nuts@googlegroups.com>
Subject: [go-nuts] synchronise read from two channels

 

Hi, I'm having a bit of a slow day... I'm trying to synchronise two reads from 
two channels and can't get my fuzzy head round the problem.

 

I have a channel containing urls (which will be feed periodically by a named 
pipe by another program) and I have a cannel which consists of a pool of 
available workers. I'd like to synchronise these and put a worker into a third 
channel for active workers if there is a url in the channel and if there is an 
available worker.

 

Ideally I'd be able to do something like:

 

go func(urlChan <-chan *url.URL, availableWorkerChan <-chan *worker, 
activeWorkerChan chan<- *worker){

for {

select{

case w := <-availableWorkerChan && w.Url = <-urlChan:

    activeWorkersChan <- w

}

}

}(a, b, c)

 

But obviously thats not right!

 

Can anyone offer my tired brain a clue?

 

Cheers!

Ben

-- 
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.
For more options, visit https://groups.google.com/d/optout.


-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to