MCPcopy Create free account
hub / github.com/encodeous/nylon / Subscribe

Method Subscribe

e2e/logging.go:115–143  ·  view source on GitHub ↗
(node string, source LogSource, pattern string, isRegex bool)

Source from the content-addressed store, hash-verified

113}
114
115func (m *LogManager) Subscribe(node string, source LogSource, pattern string, isRegex bool) (*LogSubscription, error) {
116 m.mu.Lock()
117 defer m.mu.Unlock()
118
119 key := sourceKey{node, source}
120 if _, ok := m.subscribers[key]; ok {
121 return nil, fmt.Errorf("node %s source %s already has a subscriber", node, source)
122 }
123
124 sub := &LogSubscription{
125 Node: node,
126 Source: source,
127 MatchCh: make(chan struct{}, 1),
128 }
129 if isRegex {
130 re, err := regexp.Compile(pattern)
131 if err != nil {
132 return nil, err
133 }
134 sub.Regex = re
135 } else {
136 sub.Pattern = pattern
137 }
138
139 m.subscribers[key] = sub
140 m.checkMatchLocked(key)
141
142 return sub, nil
143}
144
145func (m *LogManager) Unsubscribe(sub *LogSubscription) {
146 m.mu.Lock()

Callers 1

waitForMethod · 0.80

Calls 1

checkMatchLockedMethod · 0.95

Tested by

no test coverage detected