Unverified Commit 49bcb5fb authored by Péter Szilágyi's avatar Péter Szilágyi Committed by GitHub

Merge pull request #16228 from karalabe/faucet-background-skip

cmd/faucet: update state in background, skip when busy
parents d520bf45 6f13e515
...@@ -533,9 +533,11 @@ func (f *faucet) loop() { ...@@ -533,9 +533,11 @@ func (f *faucet) loop() {
} }
defer sub.Unsubscribe() defer sub.Unsubscribe()
for { // Start a goroutine to update the state from head notifications in the background
select { update := make(chan *types.Header)
case head := <-heads:
go func() {
for head := range update {
// New chain head arrived, query the current stats and stream to clients // New chain head arrived, query the current stats and stream to clients
var ( var (
balance *big.Int balance *big.Int
...@@ -588,6 +590,17 @@ func (f *faucet) loop() { ...@@ -588,6 +590,17 @@ func (f *faucet) loop() {
} }
} }
f.lock.RUnlock() f.lock.RUnlock()
}
}()
// Wait for various events and assing to the appropriate background threads
for {
select {
case head := <-heads:
// New head arrived, send if for state update if there's none running
select {
case update <- head:
default:
}
case <-f.update: case <-f.update:
// Pending requests updated, stream to clients // Pending requests updated, stream to clients
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment