gocrawl(开源爬虫类库)的一种方案
https://github.com/PuerkitoBio/gocrawl/blob/master/popchannel.go ```
type popChannel chan []*URLContext
// The stack function ensures the specified URLs are added to the pop channel
// with minimal blocking (since the channel is stacked, it is virtually equivalent
// to an infinitely buffered channel).
func (pc popChannel) stack(cmd ...*URLContext) {
toStack := cmd
for {
select {
case pc <- toStack:
return
case old := <-pc:
// Content of the channel got emptied and is now in old, so append whatever
// is in toStack to it, so that it can either be inserted in the channel,
// or appended to some other content that got through in the meantime.
toStack = append(old, toStack...)
}
}
}
```