Other: Safer user types

This commit is contained in:
James Houlahan
2022-10-12 00:20:04 +02:00
parent 4dc32dc7f2
commit fd63611b41
35 changed files with 1253 additions and 771 deletions

View File

@ -2,6 +2,7 @@ package try
import (
"fmt"
"sync"
"github.com/sirupsen/logrus"
)
@ -47,3 +48,31 @@ func catch(handlers ...func() error) {
}
}
}
type Group struct {
mu sync.Mutex
}
func (wg *Group) GoTry(fn func(bool)) {
if wg.mu.TryLock() {
go func() {
defer wg.mu.Unlock()
fn(true)
}()
} else {
go fn(false)
}
}
func (wg *Group) Lock() {
wg.mu.Lock()
}
func (wg *Group) Unlock() {
wg.mu.Unlock()
}
func (wg *Group) Wait() {
wg.mu.Lock()
defer wg.mu.Unlock()
}