-
Notifications
You must be signed in to change notification settings - Fork 0
/
lock-impl.go
53 lines (43 loc) · 1.03 KB
/
lock-impl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* Copyright (c) 2024.
* Created by Andy Pangaribuan <https://github.com/apangaribuan>.
*
* This product is protected by copyright and distributed under
* licenses restricting copying, distribution and decompilation.
* All Rights Reserved.
*/
package lock
import (
"github.com/andypangaribuan/gmod/ice"
"github.com/pkg/errors"
)
func (slf *stuLock) NewOpt() ice.LockOpt {
return new(stuLockOpt)
}
func (slf *stuLock) Tx(id string, opt ...ice.LockOpt) (ice.LockInstance, error) {
if isTxOnDevMode() {
return new(stuLockInstance), nil
}
if txLockEngine == nil {
return new(stuLockInstance), errors.New("doesn't have lock engine, please set from gm.Conf.SetTxLockEngine")
}
var (
timeout = dvalTxTimeout
tryFor = dvalTxTryFor
prefix string
)
for _, o := range opt {
if v, ok := o.(*stuLockOpt); ok {
if v.timeout != nil {
timeout = *v.timeout
}
if v.tryFor != nil {
tryFor = v.tryFor
}
if v.prefix != nil {
prefix = *v.prefix
}
}
}
return getTxLock(prefix+id, timeout, tryFor)
}