mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-11 12:15:34 +08:00
Add more logic to the way code is organized. /pkg -- library code not directly connected to micromdm /mdm -- packages meant for the services devices interract with. The MDM protocol. /dep -- DEP API and related packages. /platform -- Core APIs the server provides. Commands API, Devices API, queue, pubsub etc. /workflow -- Packages/API that build on top of platform. Today that's the webhook package. Depending on what ends up here, the workflow folder might become its own repository.
35 lines
646 B
Go
35 lines
646 B
Go
package inmem
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/micromdm/micromdm/platform/pubsub"
|
|
)
|
|
|
|
func (p *Inmem) Subscribe(_ context.Context, name, topic string) (<-chan pubsub.Event, error) {
|
|
events := make(chan pubsub.Event)
|
|
sub := subscription{
|
|
name: name,
|
|
topic: topic,
|
|
eventChan: events,
|
|
}
|
|
p.mtx.Lock()
|
|
p.subscriptions[topic] = append(p.subscriptions[topic], sub)
|
|
p.mtx.Unlock()
|
|
|
|
return events, nil
|
|
}
|
|
|
|
func (p *Inmem) dispatch() {
|
|
for {
|
|
select {
|
|
case ev := <-p.publish:
|
|
p.mtx.Lock()
|
|
for _, sub := range p.subscriptions[ev.Topic] {
|
|
go func(s subscription) { s.eventChan <- ev }(sub)
|
|
}
|
|
p.mtx.Unlock()
|
|
}
|
|
}
|
|
}
|