Messaging service, adapters, refactoring

This commit is contained in:
2023-12-07 09:00:30 +03:00
parent cf00cfaab6
commit 08a7c9c04f
18 changed files with 623 additions and 53 deletions

View File

@@ -0,0 +1,34 @@
package discovery
// DiscoverySet a slice of initialized discovery services.
//
//goland:noinspection GoNameStartsWithPackageName
type DiscoverySet []*Discovery
// NewNodes returns channel with newly discovered node ips.
func (d DiscoverySet) NewNodes() NewNodes {
res := make(chan string, 20)
for _, discovery := range d {
go func(discovery *Discovery) {
for node := range discovery.NewNodes() {
if len(res) == cap(res) {
panic("knownNodes from discovery set not reading!")
}
res <- node
}
}(discovery)
}
return res
}
// FailNodes accept a channel with ip of nodes, that was failed (lost or canceled connection).
func (d DiscoverySet) FailNodes(ch chan string) {
for addr := range ch {
for _, discovery := range d {
discovery.FailNode(addr)
}
}
}