Commit fc3b2757
fc3b27572e58Merged
Svyatoslav Dumchenko <[email protected]> ยท 5 years ago ยท 2 files ยท +1 added ยท ~1 modified
Description
add pubsub tests
Details
- Commit
- fc3b27572e58
- Parent
- f341fc219c42
pkg/pubsub/pubsub.gomodifiedView file
@@ -14,21 +14,26 @@
1414
subs map[string][]chan ReleaseStatus1515
}1616
17+
// NewReleasePubSub creates new PubSub structure.1718
func NewReleasePubSub() *ReleasePubSub {1819
return &ReleasePubSub{20+
mu: sync.RWMutex{},1921
subs: make(map[string][]chan ReleaseStatus),2022
}2123
}2224
25+
// Subscribe adds new subscription for defined key and returns notification channel.2326
func (ps *ReleasePubSub) Subscribe(release string) <-chan ReleaseStatus {2427
ps.mu.Lock()2528
defer ps.mu.Unlock()2629
2730
ch := make(chan ReleaseStatus, 1)2831
ps.subs[release] = append(ps.subs[release], ch)32+
2933
return ch3034
}3135
36+
// publish publishes notification for all subscribers.3237
func (ps *ReleasePubSub) publish(release string, status ReleaseStatus) {3338
ps.mu.Lock()3439
defer ps.mu.Unlock()@@ -39,10 +44,12 @@
3944
}4045
}4146
47+
// PublishSuccess publishes success notification for all subscribers.4248
func (ps *ReleasePubSub) PublishSuccess(release string) {4349
ps.publish(release, ReleaseSuccess)4450
}4551
52+
// PublishFailed publishes failed notification for all subscribers.4653
func (ps *ReleasePubSub) PublishFailed(release string) {4754
ps.publish(release, ReleaseFailed)4855
}pkg/pubsub/pubsub_test.goaddedView file
Loading diffโฆ