-
Notifications
You must be signed in to change notification settings - Fork 0
/
link.go
58 lines (50 loc) · 914 Bytes
/
link.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
54
55
56
57
58
package graph
import (
"github.com/15mga/kiwi/ds"
"github.com/15mga/kiwi/util"
)
type ILink interface {
IGraphElem
In() IIn
Out() IOut
Transfer(msg IMsg) *util.Err
AddFilter(fn func(IMsg) *util.Err)
}
func newLink(g IGraph, name string, out IOut, in IIn) ILink {
return &link{
IGraphElem: newGraphElem(g, name),
out: out,
in: in,
}
}
type link struct {
IGraphElem
in IIn
out IOut
filter *ds.FnErrLink1[IMsg]
}
func (l *link) In() IIn {
return l.in
}
func (l *link) Out() IOut {
return l.out
}
func (l *link) Transfer(msg IMsg) *util.Err {
if !l.Enabled() {
return nil
}
if l.filter != nil {
err := l.filter.Invoke(msg)
if err != nil {
err.AddParam("link", l.Path())
return err
}
}
return l.in.Receive(msg)
}
func (l *link) AddFilter(fn func(IMsg) *util.Err) {
if l.filter == nil {
l.filter = ds.NewFnErrLink1[IMsg]()
}
l.filter.Push(fn)
}