You can not select more than 25 topics
Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
- package lock
-
- type LockChainOperator struct {
- chainList []Lock
- lockedList []Lock
- ctx *LockContext
- }
-
- func NewLockChainOperator(ctx *LockContext) *LockChainOperator {
- return &LockChainOperator{ctx: ctx}
- }
-
- func (b *LockChainOperator) Add(l Lock) *LockChainOperator {
- b.chainList = append(b.chainList, l)
- return b
- }
-
- func (b *LockChainOperator) Lock() string {
- for i := 0; i < len(b.chainList); i++ {
- l := b.chainList[i]
- if !l.IsMatch(b.ctx) {
- continue
- }
-
- if errCode := l.Lock(b.ctx); errCode != "" {
- b.Unlock()
- return errCode
- }
- b.lockedList = append(b.lockedList, l)
- }
- return ""
- }
-
- func (b *LockChainOperator) Unlock() error {
- if b.chainList == nil || len(b.chainList) == 0 {
- return nil
- }
- for j := len(b.lockedList) - 1; j >= 0; j-- {
- b.lockedList[j].Unlock(b.ctx)
- }
- return nil
- }
|