Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/badu/fanout
Fan Out design pattern (aka broadcasting channel using generics)
https://github.com/badu/fanout
fanout go golang pubsub
Last synced: 8 days ago
JSON representation
Fan Out design pattern (aka broadcasting channel using generics)
- Host: GitHub
- URL: https://github.com/badu/fanout
- Owner: badu
- License: mit
- Created: 2023-03-23T08:06:26.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-03-24T12:03:57.000Z (almost 2 years ago)
- Last Synced: 2024-11-18T07:06:19.294Z (2 months ago)
- Topics: fanout, go, golang, pubsub
- Language: Go
- Homepage:
- Size: 3.91 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Fan Out
Fan Out design pattern, using channels with generics.
## What problem does it solve?
Fan Out pattern is a software architecture pattern that involves distributing data (messages / payloads) from a single
sender (publisher) to multiple receivers (listeners).Each recipient receives a copy of the message - if your `payload` is a pointer, that would violate the pattern.
The Fan Out pattern is useful in situations where multiple components of a system need to `react` to the same `event` or
receive the same `data`.This is a naive implementation of the Fan Out pattern, using channels and generics.
In its shortest form, it looks like this:
```go
package mypackfunc FanOut[T any](from <-chan T, to ...chan<- T) {
for v := range from {
for _, ch := range to {
ch <- v
}
}
}```
## Usage
`go get github.com/badu/fanout`
T. B. D.