Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mdw-go/funnel
fun + go channels = funnel
https://github.com/mdw-go/funnel
Last synced: 14 days ago
JSON representation
fun + go channels = funnel
- Host: GitHub
- URL: https://github.com/mdw-go/funnel
- Owner: mdw-go
- Created: 2022-10-19T15:52:46.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-19T15:17:04.000Z (30 days ago)
- Last Synced: 2024-10-20T14:53:49.614Z (29 days ago)
- Language: Go
- Size: 29.3 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# funnel
A generic fan-out/fan-in library in Go.
Allows for easy implementation of the fan-out/fan-in pattern described on the [Go blog](https://go.dev/blog/pipelines).
How to use:
1. Load up (and CLOSE!) an input channel (optionally in a separate goroutine).
2. Provide the desired number of workers, the input channel, and a function that will process each item from the input channel to the FanOut function.
3. Read processed items from the channel returned by the FanOut function until it is consumed.See the test file for an example.
Notes:
- Responsibility to close the input channel rests with the caller.
- Responsibility to close the output channel rests with this library.
- Passing `0` as the number of workers will result in a panic.
- While each item provided to the input channel will be processed, the order of those items on the output channel is non-deterministic.
- Calling FanOut will result in `2N+1` goroutines, where N is the number of workers specified.
- Each goroutine created will have exited by the time the output channel has been consumed.