This commit is contained in:
Andrey Petrov 2014-05-17 16:24:12 -07:00
parent 8ec2703f3c
commit e73de7985e
2 changed files with 6 additions and 6 deletions

View File

@ -183,7 +183,7 @@ func (c *Crawler) Run(resultChan chan<- Result, numWorkers int) {
numActive++ numActive++
go func() { go func() {
address := <-c.queue.Output address := <-c.queue.Output
logger.Debugf("[%s] Worker started.", address) logger.Debugf("[%s] Work received.", address)
tempResult <- *c.handleAddress(address) tempResult <- *c.handleAddress(address)
}() }()

View File

@ -18,13 +18,13 @@ func NewQueue(filter func(string) *string, bufferSize int) *Queue {
filter: filter, filter: filter,
} }
go func(input <-chan string, output chan<- string) { go func() {
// Block until we have a next item // Block until we have a next item
nextItem := q.next() nextItem := q.next()
for { for {
select { select {
case item := <-input: case item := <-q.Input:
// New input // New input
r := q.filter(item) r := q.filter(item)
if r != nil { if r != nil {
@ -32,12 +32,12 @@ func NewQueue(filter func(string) *string, bufferSize int) *Queue {
q.overflow = append(q.overflow, *r) q.overflow = append(q.overflow, *r)
q.count++ q.count++
} }
case output <- nextItem: case q.Output <- nextItem:
// Block until we have more inputs // Block until we have more inputs
nextItem = q.next() nextItem = q.next()
} }
} }
}(q.Input, q.Output) }()
return &q return &q
} }
@ -64,7 +64,7 @@ func (q *Queue) next() string {
} }
func (q *Queue) IsEmpty() bool { func (q *Queue) IsEmpty() bool {
// FIXME: This effectively cycles the order of the output buffer. Kinda sad. // FIXME: This breaks everything, get rid of it.
if len(q.overflow) > 0 { if len(q.overflow) > 0 {
return false return false