-
Notifications
You must be signed in to change notification settings - Fork 0
/
io_helper.go
63 lines (53 loc) · 1.12 KB
/
io_helper.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
59
60
61
62
63
package loong
import (
"context"
"github.com/it512/loong/bpmn/zeebe"
)
type IoSet []IoCaller
func (io IoSet) Call(ctx context.Context, task IoTasker) error {
for _, call := range io {
if err := call.Call(ctx, task); err != nil {
return err
}
}
return nil
}
type ioer interface {
GetIoInput() []zeebe.TIoMapping
GetIoOutput() []zeebe.TIoMapping
ActivationEvaluator
IoCaller
Getter
Setter
IoTasker
}
func in(ctx context.Context, in []zeebe.TIoMapping, eval ActivationEvaluator, s Setter) error {
return Each(in, func(m zeebe.TIoMapping, _ int) error {
if m.Target != "" {
s.Set(m.Target, lazy(ctx, eval, m.Source))
}
return nil
})
}
func out(o []zeebe.TIoMapping, g Getter, s Putter) error {
return Each(o, func(m zeebe.TIoMapping, _ int) error {
if m.Target != "" {
if v, ok := g.Get(m.Source); ok {
s.Put(m.Target, v)
}
}
return nil
})
}
func io(ctx context.Context, x ioer, s Putter) (err error) {
if err = in(ctx, x.GetIoInput(), x, x); err != nil {
return
}
if err = x.Call(ctx, x); err != nil {
return
}
if err = out(x.GetIoOutput(), x, s); err != nil {
return
}
return
}