Compare commits

..
Author SHA1 Message Date
gohumble 2a10560321 🪄 fix LNURL states redundant initialization 2022-02-26 11:02:45 +01:00
2 changed files with 0 additions and 20 deletions
-7
View File
@@ -17,7 +17,6 @@ var defaultTickerCoolDown = time.Second * 10
type ResettableFunctionTicker struct {
Ticker *time.Ticker
ResetChan chan struct{} // channel used to reset the ticker
StopChan chan struct{} // channel used to stop the ticker
duration time.Duration
Started bool
name string
@@ -45,7 +44,6 @@ func GetTicker(name string, option ...ResettableFunctionTickerOption) *Resettabl
func NewResettableFunctionTicker(name string, option ...ResettableFunctionTickerOption) *ResettableFunctionTicker {
t := &ResettableFunctionTicker{
ResetChan: make(chan struct{}, 1),
StopChan: make(chan struct{}, 1),
name: name,
}
@@ -72,11 +70,6 @@ func (t *ResettableFunctionTicker) Do(f func()) {
case <-t.ResetChan:
// reset signal received. creating new ticker.
t.Ticker = time.NewTicker(t.duration)
case <-t.StopChan:
// reset signal received. creating new ticker.
t.Ticker = nil
tickerMap.Remove(t.name)
return
}
}
}()
-13
View File
@@ -3,10 +3,8 @@ package mutex
import (
"context"
"fmt"
"github.com/LightningTipBot/LightningTipBot/internal/runtime"
"net/http"
"sync"
"time"
"github.com/gorilla/mux"
@@ -120,14 +118,8 @@ func Lock(s string) {
} else {
m := &sync.Mutex{}
m.Lock()
tick := runtime.NewResettableFunctionTicker(s, runtime.WithDuration(time.Hour))
tick.Do(
func() {
Unlock(s)
})
// write into mutex map
mutexMapSync.Lock()
mutexMap.Set(fmt.Sprintf("ticker_%s", s), tick)
mutexMap.Set(s, m)
mutexMapSync.Unlock()
}
@@ -139,11 +131,6 @@ func Unlock(s string) {
mutexMapSync.Lock()
if m, ok := mutexMap.Get(s); ok {
mutexMap.Remove(s)
tickerKey := fmt.Sprintf("ticker_%s", s)
if tick, ok := mutexMap.Get(tickerKey); ok {
tick.(*runtime.ResettableFunctionTicker).StopChan <- struct{}{}
mutexMap.Remove(tickerKey)
}
m.(*sync.Mutex).Unlock()
log.Tracef("[Mutex] Unlocked %s", s)
} else {