Distributed lock
Methods that must be implemented by the custom type
// Methods that a Locker mutual exclusion lock needs to implement
type Locker interface {
// Lock acquire lock
Lock(ctx context.Context, key, threadId string, expiresIn time.Duration) bool
// Unlock release lock
Unlock(ctx context.Context, key, threadId string) bool
// Renew
KeepAlive(ctx context.Context, key, threadId string, expiresIn time.Duration) bool
}Use
import "github.com/asjard/asjard/pkg/mutex"
m := &mutext.Mutex{Locker: &customeLock{}}
m.TryLock(context.Background(), key, do, mutex.WithMaxRetries(-1))Last updated