• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

looplab / eventhorizon / 12622512440

05 Jan 2025 07:58PM UTC coverage: 27.495% (-39.9%) from 67.361%
12622512440

Pull #419

github

web-flow
Merge b3c17d928 into ac3a97277
Pull Request #419: fix(ci): update to up/download-artifact v4

1769 of 6434 relevant lines covered (27.49%)

1.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/middleware/commandhandler/lock/local_lock.go
1
// Copyright (c) 2021 - The Event Horizon authors.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
package lock
16

17
import "sync"
18

19
// LocalLock is a Lock implemention using local locking only. Not suitable for
20
// use in distributed environments.
21
type LocalLock struct {
22
        locks map[string]struct{}
23
        mu    sync.Mutex
24
}
25

26
// NewLocalLock creates a new LocalLock.
27
func NewLocalLock() *LocalLock {
×
28
        return &LocalLock{
×
29
                locks: map[string]struct{}{},
×
30
        }
×
31
}
×
32

33
// Lock implements the Lock method of the Lock interface.
34
func (l *LocalLock) Lock(id string) error {
×
35
        l.mu.Lock()
×
36
        defer l.mu.Unlock()
×
37

×
38
        if _, ok := l.locks[id]; ok {
×
39
                return ErrLockExists
×
40
        }
×
41

42
        l.locks[id] = struct{}{}
×
43

×
44
        return nil
×
45
}
46

47
// Unlock implements the Unlock method of the Lock interface.
48
func (l *LocalLock) Unlock(id string) error {
×
49
        l.mu.Lock()
×
50
        defer l.mu.Unlock()
×
51

×
52
        if _, ok := l.locks[id]; !ok {
×
53
                return ErrNoLockExists
×
54
        }
×
55

56
        delete(l.locks, id)
×
57

×
58
        return nil
×
59
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc