mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
adding docs to AsyncFilter
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
parent
e7ea81d945
commit
7e96294f17
1 changed files with 14 additions and 10 deletions
|
|
@ -152,8 +152,18 @@ func (f *filterIter) Next() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// AsyncFilter wraps an iterator such that Next only returns nodes for which
|
||||
// AsyncFilterIter wraps an iterator such that Next only returns nodes for which
|
||||
// the 'check' function returns a (possibly modified) node.
|
||||
type AsyncFilterIter struct {
|
||||
it Iterator // the iterator to filter
|
||||
check func(*Node) (*Node, error) // the blocking check function
|
||||
slots chan struct{} // the slots for parallel checking
|
||||
passed chan *Node // channel to collect passed nodes
|
||||
closed chan struct{} // channel to override passed when closing
|
||||
buffer *Node // buffer to serve the Node call
|
||||
}
|
||||
|
||||
// AsyncFilter creates an iterator which checks nodes in parallel.
|
||||
func AsyncFilter(it Iterator, check func(*Node) (*Node, error), workers int) Iterator {
|
||||
f := &AsyncFilterIter{it, check, make(chan struct{}, workers), make(chan *Node), make(chan struct{}), nil}
|
||||
|
||||
|
|
@ -195,24 +205,18 @@ func AsyncFilter(it Iterator, check func(*Node) (*Node, error), workers int) Ite
|
|||
return f
|
||||
}
|
||||
|
||||
type AsyncFilterIter struct {
|
||||
it Iterator
|
||||
check func(*Node) (*Node, error)
|
||||
slots chan struct{}
|
||||
passed chan *Node
|
||||
closed chan struct{}
|
||||
buffer *Node
|
||||
}
|
||||
|
||||
// Next blocks until a node is available or the iterator is closed.
|
||||
func (f *AsyncFilterIter) Next() bool {
|
||||
f.buffer = <-f.passed
|
||||
return f.buffer != nil
|
||||
}
|
||||
|
||||
// Node returns the current node.
|
||||
func (f *AsyncFilterIter) Node() *Node {
|
||||
return f.buffer
|
||||
}
|
||||
|
||||
// Close ends the iterator, also closing the wrapped iterator.
|
||||
func (f *AsyncFilterIter) Close() {
|
||||
f.it.Close()
|
||||
close(f.closed) // override the passed channel
|
||||
|
|
|
|||
Loading…
Reference in a new issue