Skip to content

Commit

Permalink
Merge pull request #10 from storage-lock/dev
Browse files Browse the repository at this point in the history
feat: 为memory-locks增加创建锁时指定选项
  • Loading branch information
CC11001100 authored Aug 30, 2023
2 parents d7b6de4 + 1e3a45d commit db54915
Showing 1 changed file with 17 additions and 5 deletions.
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

0 comments on commit db54915

Please sign in to comment.