• 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/eventhandler/async/middleware.go
1
// Copyright (c) 2017 - 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 async
16

17
import (
18
        "context"
19
        "fmt"
20

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

24
// NewMiddleware returns a new async handling middleware that returns any errors
25
// on a error channel.
26
func NewMiddleware() (eh.EventHandlerMiddleware, chan *Error) {
×
27
        errCh := make(chan *Error, 20)
×
28

×
29
        return eh.EventHandlerMiddleware(func(h eh.EventHandler) eh.EventHandler {
×
30
                return &eventHandler{h, errCh}
×
31
        }), errCh
×
32
}
33

34
type eventHandler struct {
35
        eh.EventHandler
36
        errCh chan *Error
37
}
38

39
// InnerHandler implements EventHandlerChain
40
func (h *eventHandler) InnerHandler() eh.EventHandler {
×
41
        return h.EventHandler
×
42
}
×
43

44
// HandleEvent implements the HandleEvent method of the EventHandler.
45
func (h *eventHandler) HandleEvent(ctx context.Context, event eh.Event) error {
×
46
        go func() {
×
47
                if err := h.EventHandler.HandleEvent(ctx, event); err != nil {
×
48
                        // Always try to deliver errors.
×
49
                        h.errCh <- &Error{err, ctx, event}
×
50
                }
×
51
        }()
52

53
        return nil
×
54
}
55

56
// Error is an async error containing the error and the event.
57
type Error struct {
58
        // Err is the error that happened when handling the event.
59
        Err error
60
        // Ctx is the context used when the error happened.
61
        Ctx context.Context
62
        // Event is the event handeled when the error happened.
63
        Event eh.Event
64
}
65

66
// Error implements the Error method of the error interface.
67
func (e *Error) Error() string {
×
68
        return fmt.Sprintf("%s: %s", e.Event.String(), e.Err.Error())
×
69
}
×
70

71
// Unwrap implements the errors.Unwrap method.
72
func (e *Error) Unwrap() error {
×
73
        return e.Err
×
74
}
×
75

76
// Cause implements the github.com/pkg/errors Unwrap method.
77
func (e *Error) Cause() error {
×
78
        return e.Unwrap()
×
79
}
×
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