• 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/middleware.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 (
18
        "context"
19
        "log"
20

21
        eh "github.com/looplab/eventhorizon"
22
)
23

24
// NewMiddleware returns a new lock middle ware using a provided lock implementation.
25
// Useful for handling only one command per aggregate ID at a time.
26
func NewMiddleware(l Lock) eh.CommandHandlerMiddleware {
×
27
        return eh.CommandHandlerMiddleware(func(h eh.CommandHandler) eh.CommandHandler {
×
28
                return eh.CommandHandlerFunc(func(ctx context.Context, cmd eh.Command) error {
×
29
                        if err := l.Lock(cmd.AggregateID().String()); err != nil {
×
30
                                return err
×
31
                        }
×
32
                        defer func() {
×
33
                                if err := l.Unlock(cmd.AggregateID().String()); err != nil {
×
34
                                        log.Printf("eventhorizon: could not unlock command '%s': %s", cmd.AggregateID(), err)
×
35
                                }
×
36
                        }()
37

38
                        return h.HandleCommand(ctx, cmd)
×
39
                })
40
        })
41
}
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

© 2025 Coveralls, Inc