mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 17:33:47 +00:00
whisper: Exit api.run when whisper is stopped
This commit is contained in:
parent
5cf75a30c1
commit
c15bf122e4
2 changed files with 28 additions and 20 deletions
|
|
@ -69,9 +69,12 @@ func NewPublicWhisperAPI(w *Whisper) *PublicWhisperAPI {
|
||||||
// this loop deletes filter that have not been used within filterTimeout
|
// this loop deletes filter that have not been used within filterTimeout
|
||||||
func (api *PublicWhisperAPI) run() {
|
func (api *PublicWhisperAPI) run() {
|
||||||
timeout := time.NewTicker(2 * time.Minute)
|
timeout := time.NewTicker(2 * time.Minute)
|
||||||
|
defer timeout.Stop()
|
||||||
for {
|
for {
|
||||||
<-timeout.C
|
select {
|
||||||
|
case <-api.w.quit:
|
||||||
|
return
|
||||||
|
case <-timeout.C:
|
||||||
api.mu.Lock()
|
api.mu.Lock()
|
||||||
for id, lastUsed := range api.lastUsed {
|
for id, lastUsed := range api.lastUsed {
|
||||||
if time.Since(lastUsed).Seconds() >= filterTimeout {
|
if time.Since(lastUsed).Seconds() >= filterTimeout {
|
||||||
|
|
@ -85,6 +88,7 @@ func (api *PublicWhisperAPI) run() {
|
||||||
api.mu.Unlock()
|
api.mu.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Version returns the Whisper sub-protocol version.
|
// Version returns the Whisper sub-protocol version.
|
||||||
func (api *PublicWhisperAPI) Version(ctx context.Context) string {
|
func (api *PublicWhisperAPI) Version(ctx context.Context) string {
|
||||||
|
|
|
||||||
|
|
@ -70,9 +70,12 @@ func NewPublicWhisperAPI(w *Whisper) *PublicWhisperAPI {
|
||||||
// this loop deletes filter that have not been used within filterTimeout
|
// this loop deletes filter that have not been used within filterTimeout
|
||||||
func (api *PublicWhisperAPI) run() {
|
func (api *PublicWhisperAPI) run() {
|
||||||
timeout := time.NewTicker(2 * time.Minute)
|
timeout := time.NewTicker(2 * time.Minute)
|
||||||
|
defer timeout.Stop()
|
||||||
for {
|
for {
|
||||||
<-timeout.C
|
select {
|
||||||
|
case <-api.w.quit:
|
||||||
|
return
|
||||||
|
case <-timeout.C:
|
||||||
api.mu.Lock()
|
api.mu.Lock()
|
||||||
for id, lastUsed := range api.lastUsed {
|
for id, lastUsed := range api.lastUsed {
|
||||||
if time.Since(lastUsed).Seconds() >= filterTimeout {
|
if time.Since(lastUsed).Seconds() >= filterTimeout {
|
||||||
|
|
@ -86,6 +89,7 @@ func (api *PublicWhisperAPI) run() {
|
||||||
api.mu.Unlock()
|
api.mu.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Version returns the Whisper sub-protocol version.
|
// Version returns the Whisper sub-protocol version.
|
||||||
func (api *PublicWhisperAPI) Version(ctx context.Context) string {
|
func (api *PublicWhisperAPI) Version(ctx context.Context) string {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue