Skip to content

Commit 49bcb5f

Browse files
authored
Merge pull request #16228 from karalabe/faucet-background-skip
cmd/faucet: update state in background, skip when busy
2 parents d520bf4 + 6f13e51 commit 49bcb5f

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

cmd/faucet/faucet.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,9 +533,11 @@ func (f *faucet) loop() {
533533
}
534534
defer sub.Unsubscribe()
535535

536-
for {
537-
select {
538-
case head := <-heads:
536+
// Start a goroutine to update the state from head notifications in the background
537+
update := make(chan *types.Header)
538+
539+
go func() {
540+
for head := range update {
539541
// New chain head arrived, query the current stats and stream to clients
540542
var (
541543
balance *big.Int
@@ -588,6 +590,17 @@ func (f *faucet) loop() {
588590
}
589591
}
590592
f.lock.RUnlock()
593+
}
594+
}()
595+
// Wait for various events and assing to the appropriate background threads
596+
for {
597+
select {
598+
case head := <-heads:
599+
// New head arrived, send if for state update if there's none running
600+
select {
601+
case update <- head:
602+
default:
603+
}
591604

592605
case <-f.update:
593606
// Pending requests updated, stream to clients

0 commit comments

Comments
 (0)