Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Rake ¶
type Rake struct {
// contains filtered or unexported fields
}
Rake represents a fanned out circular pipe network with a flexibly adjusting buffer. Any item is processed once only - items seen before are filtered out.
A Rake may be used e.g. as a crawling Crawler where every link shall be visited only once.
Example (Chained) ¶
var r *Rake crawl := func(item Any) { if false { log.Println("have:", item) } for i := 0; i < rand.Intn(9)+2; i++ { r.Feed(rand.Intn(2000)) // up to 10 new numbers < 2.000 } time.Sleep(time.Millisecond * 10) } r = New(nil, nil, 80).Rake(crawl).Feed(1) <-r.Done() fmt.Println("Done")
Output: Done
Example (Closure) ¶
var r *Rake crawl := func(item Any) { if false { log.Println("have:", item) } for i := 0; i < rand.Intn(9)+2; i++ { r.Feed(rand.Intn(2000)) // up to 10 new numbers < 2.000 } time.Sleep(time.Millisecond * 10) } r = New(crawl, nil, 80) r.Feed(1) <-r.Done() fmt.Println("Done")
Output: Done
func New ¶
New returns a (pointer to a) new operational Rake.
`rake` is the operation to be executed in parallel on any item which has not been seen before. Have it use `myrake.Feed(items...)` in order to provide feed-back.
`attr` allows to specify an attribute for the seen filter. Pass `nil` to filter on any item itself.
`somany` is the # of parallel processes - the parallelism of the network built by Rake, the # of parallel raking endpoints of the Rake.
func (*Rake) Attr ¶ added in v0.2.2
Attr sets the (optional) attribute to discriminate 'seen'.
`attr` allows to specify an attribute for the 'seen' filter. If not set 'seen' will discriminate any item by itself.
Seen panics iff called after first nonempty `Feed(...)`
func (*Rake) Done ¶
func (my *Rake) Done() (done <-chan struct{})
Done returns a channel which will be signalled and closed when traffic has subsided, nothing is left to be processed and consequently all goroutines have terminated.
func (*Rake) Rake ¶ added in v0.2.2
Rake sets the rake function to be applied (in parallel).
`rake` is the operation to be executed in parallel on any item which has not been seen before.
You may provide `nil` here and call `Rake(..)` later to provide it. Or have it use `myrake.Feed(items...)` in order to provide feed-back.
Rake panics iff called after first nonempty `Feed(...)`