Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 为memory-locks增加创建锁时指定选项 #10

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions global.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,29 @@ var (

// NewLock 从DSN创建锁
func NewLock(ctx context.Context, lockId string) (*storage_lock.StorageLock, error) {
init, err := globalLockFactory.GetOrInit(ctx, "x", func(ctx context.Context) (*storage_lock_factory.StorageLockFactory[any], error) {
init, err := GetLockFactory(ctx)
if err != nil {
return nil, err
}
return init.CreateLock(lockId)
}

func NewLockWithOptions(ctx context.Context, lockId string, options *storage_lock.StorageLockOptions) (*storage_lock.StorageLock, error) {
init, err := GetLockFactory(ctx)
if err != nil {
return nil, err
}
return init.CreateLockWithOptions(lockId, options)
}

func GetLockFactory(ctx context.Context) (*storage_lock_factory.StorageLockFactory[any], error) {
return globalLockFactory.GetOrInit(ctx, "x", func(ctx context.Context) (*storage_lock_factory.StorageLockFactory[any], error) {
factory, err := NewLockFactory()
if err != nil {
return nil, err
}
return factory.StorageLockFactory, nil
})
if err != nil {
return nil, err
}
return init.CreateLock(lockId)
}

func GetGlobalLockFactory() *storage_lock_factory.StorageLockFactoryBeanFactory[string, any] {
Expand Down