aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2018-03-02 18:13:19 +0800
committerGitHub <noreply@github.com>2018-03-02 18:13:19 +0800
commit49bcb5fbd55e3e15c534fac13d2d65829319298a (patch)
treea6b895c8b495761a8a92d78629f0e6b7bae8fd2c /cmd
parentd520bf45038ec8f02dd255bea038c5785f7290e0 (diff)
parent6f13e515f40ef84ff277d373488c99de49e33f18 (diff)
downloaddexon-49bcb5fbd55e3e15c534fac13d2d65829319298a.tar
dexon-49bcb5fbd55e3e15c534fac13d2d65829319298a.tar.gz
dexon-49bcb5fbd55e3e15c534fac13d2d65829319298a.tar.bz2
dexon-49bcb5fbd55e3e15c534fac13d2d65829319298a.tar.lz
dexon-49bcb5fbd55e3e15c534fac13d2d65829319298a.tar.xz
dexon-49bcb5fbd55e3e15c534fac13d2d65829319298a.tar.zst
dexon-49bcb5fbd55e3e15c534fac13d2d65829319298a.zip
Merge pull request #16228 from karalabe/faucet-background-skip
cmd/faucet: update state in background, skip when busy
Diffstat (limited to 'cmd')
-rw-r--r--cmd/faucet/faucet.go19
1 files changed, 16 insertions, 3 deletions
diff --git a/cmd/faucet/faucet.go b/cmd/faucet/faucet.go
index 095668c86..5bad09bbd 100644
--- a/cmd/faucet/faucet.go
+++ b/cmd/faucet/faucet.go
@@ -533,9 +533,11 @@ func (f *faucet) loop() {
}
defer sub.Unsubscribe()
- for {
- select {
- case head := <-heads:
+ // Start a goroutine to update the state from head notifications in the background
+ update := make(chan *types.Header)
+
+ go func() {
+ for head := range update {
// New chain head arrived, query the current stats and stream to clients
var (
balance *big.Int
@@ -588,6 +590,17 @@ func (f *faucet) loop() {
}
}
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:
// Pending requests updated, stream to clients