Debian Codegraph @

ami/handler.go

raw symbols SCIP
1 package ami
2
3 import "context"
4
5 func SubscribeChan(c chan *Message, names ...string) SubscribeFunc {
6 m := make(map[string]struct{}, len(names))
7 for _, v := range names {
8 m[v] = struct{}{}
9 }
10 filter := func(ctx context.Context, msg *Message) bool {
11 _, ok := m[msg.Name]
12 return ok
13 }
14 if len(names) == 0 {
15 filter = func(ctx context.Context, msg *Message) bool {
16 return true
17 }
18 }
19 return func(ctx context.Context, msg *Message) bool {
20 if filter(ctx, msg) {
21 c <- msg
22 }
23
24 return true
25 }
26 }
27
28 func SubscribeFullyBootedChanOnce(c chan *Message) SubscribeFunc {
29 return func(ctx context.Context, msg *Message) bool {
30 if msg.Name == "FullyBooted" {
31 c <- msg
32 return false
33 }
34 return true
35 }
36 }