This commit is contained in:
parent
4e09037e9f
commit
6288d01c0e
|
@ -27,7 +27,7 @@ func ReadAccountId(r io.Reader) AccountId {
|
|||
case ACCOUNT_TYPE_BOTH:
|
||||
return AccountId{t, ReadUInt64(r), ReadByteSlice(r)}
|
||||
default:
|
||||
panicf("Unknown AccountId type %x", t)
|
||||
Panicf("Unknown AccountId type %x", t)
|
||||
return AccountId{}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ func ReadAdjustment(r io.Reader) Adjustment {
|
|||
VoteB: ReadVote(r),
|
||||
}
|
||||
default:
|
||||
panicf("Unknown Adjustment type %x", t)
|
||||
Panicf("Unknown Adjustment type %x", t)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ func ReadTx(r io.Reader) Tx {
|
|||
Signature: ReadSignature(r),
|
||||
}
|
||||
default:
|
||||
panicf("Unknown Tx type %x", t)
|
||||
Panicf("Unknown Tx type %x", t)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package common
|
|||
|
||||
import (
|
||||
"time"
|
||||
"sync"
|
||||
)
|
||||
|
||||
/* Debouncer */
|
||||
|
@ -9,6 +10,7 @@ type Debouncer struct {
|
|||
Ch chan struct{}
|
||||
quit chan struct{}
|
||||
dur time.Duration
|
||||
mtx sync.Mutex
|
||||
timer *time.Timer
|
||||
}
|
||||
|
||||
|
@ -16,6 +18,7 @@ func NewDebouncer(dur time.Duration) *Debouncer {
|
|||
var timer *time.Timer
|
||||
var ch = make(chan struct{})
|
||||
var quit = make(chan struct{})
|
||||
var mtx sync.Mutex
|
||||
fire := func() {
|
||||
go func() {
|
||||
select {
|
||||
|
@ -23,17 +26,20 @@ func NewDebouncer(dur time.Duration) *Debouncer {
|
|||
case <-quit:
|
||||
}
|
||||
}()
|
||||
mtx.Lock(); defer mtx.Unlock()
|
||||
timer.Reset(dur)
|
||||
}
|
||||
timer = time.AfterFunc(dur, fire)
|
||||
return &Debouncer{Ch:ch, dur:dur, quit:quit, timer:timer}
|
||||
return &Debouncer{Ch:ch, dur:dur, quit:quit, mtx:mtx, timer:timer}
|
||||
}
|
||||
|
||||
func (d *Debouncer) Reset() {
|
||||
d.mtx.Lock(); defer d.mtx.Unlock()
|
||||
d.timer.Reset(d.dur)
|
||||
}
|
||||
|
||||
func (d *Debouncer) Stop() bool {
|
||||
d.mtx.Lock(); defer d.mtx.Unlock()
|
||||
close(d.quit)
|
||||
return d.timer.Stop()
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ func (pq *priorityQueue) Pop() interface{} {
|
|||
return item
|
||||
}
|
||||
|
||||
func (pq *priorityQueue) Update(item *pqItem, value ByteSlice, priority int) {
|
||||
func (pq *priorityQueue) Update(item *pqItem, value interface{}, priority int) {
|
||||
heap.Remove(pq, item.index)
|
||||
item.value = value
|
||||
item.priority = priority
|
||||
|
|
|
@ -4,6 +4,6 @@ import (
|
|||
"fmt"
|
||||
)
|
||||
|
||||
func panicf(s string, args ...interface{}) {
|
||||
func Panicf(s string, args ...interface{}) {
|
||||
panic(fmt.Sprintf(s, args...))
|
||||
}
|
||||
|
|
|
@ -95,6 +95,9 @@ func (t *IAVLTree) Copy() Tree {
|
|||
return &IAVLTree{db:t.db, root:t.root}
|
||||
}
|
||||
|
||||
// Traverses all the nodes of the tree in prefix order.
|
||||
// return true from cb to halt iteration.
|
||||
// node.Height() == 0 if you just want a value node.
|
||||
func (t *IAVLTree) Traverse(cb func(Node) bool) {
|
||||
if t.root == nil { return }
|
||||
t.root.traverse(t.db, cb)
|
||||
|
@ -104,11 +107,12 @@ func (t *IAVLTree) Values() <-chan Value {
|
|||
root := t.root
|
||||
ch := make(chan Value)
|
||||
go func() {
|
||||
root.traverse(func(n Node) {
|
||||
root.traverse(t.db, func(n Node) bool {
|
||||
if n.Height() == 0 { ch <- n.Value() }
|
||||
return true
|
||||
})
|
||||
close(ch)
|
||||
}
|
||||
}()
|
||||
return ch
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue