subscribe registers a waiter for the wait endpoint and returns a channel and an unsubscribe function. The caller must call unsubscribe when done.
(f MessageFilter)
| 83 | // subscribe registers a waiter for the wait endpoint and returns a channel and |
| 84 | // an unsubscribe function. The caller must call unsubscribe when done. |
| 85 | func (m *Module) subscribe(f MessageFilter) (<-chan event.Event, func()) { |
| 86 | ch := make(chan event.Event, 1) |
| 87 | w := &waiter{filter: f, ch: ch} |
| 88 | m.mu.Lock() |
| 89 | m.waiters = append(m.waiters, w) |
| 90 | m.mu.Unlock() |
| 91 | return ch, func() { |
| 92 | m.mu.Lock() |
| 93 | defer m.mu.Unlock() |
| 94 | for i, ww := range m.waiters { |
| 95 | if ww == w { |
| 96 | m.waiters = append(m.waiters[:i], m.waiters[i+1:]...) |
| 97 | return |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | func (m *Module) PreviewMapper() event.PreviewMapper { |
| 104 | return &previewMapper{} |
no outgoing calls
no test coverage detected