status-go/mailserver/ticker.go
Adam Babik 38a60135b2 Add asymmetric key support for MailServer requests (#1075)
* add Asymmetric Key support for MailServer requests

* remove deprecated notice

* fix linter

* refactoring Whisper config related to MailServer

* fix race condition
2018-07-04 11:30:57 +02:00

34 lines
425 B
Go

package mailserver
import (
"sync"
"time"
)
type ticker struct {
mu sync.RWMutex
timeTicker *time.Ticker
}
func (t *ticker) run(period time.Duration, fn func()) {
if t.timeTicker != nil {
return
}
tt := time.NewTicker(period)
t.mu.Lock()
t.timeTicker = tt
t.mu.Unlock()
go func() {
for range tt.C {
fn()
}
}()
}
func (t *ticker) stop() {
t.mu.RLock()
t.timeTicker.Stop()
t.mu.RUnlock()
}