https://github.com/equalsgibson/concur
Easily run concurrent goroutines safely
https://github.com/equalsgibson/concur
concurrency-patterns golang golang-libary
Last synced: 5 months ago
JSON representation
Easily run concurrent goroutines safely
- Host: GitHub
- URL: https://github.com/equalsgibson/concur
- Owner: equalsgibson
- License: gpl-3.0
- Created: 2024-03-09T15:05:27.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-02-16T01:31:52.000Z (over 1 year ago)
- Last Synced: 2025-02-16T02:24:46.846Z (over 1 year ago)
- Topics: concurrency-patterns, golang, golang-libary
- Language: Go
- Homepage:
- Size: 42 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#
Easily run concurrent goroutines safely
- **Easy to use**: Get up and running with the library in minutes
- **Intuitive**: Get access to a powerful pattern within software development, without encountering common pitfalls or mistakes!
- **Actively developed**: Ideas and contributions welcomed!
---
[![Go][golang]][golang-url]
[![Go Reference][goref]][goref-url]
[![Go Report Card][goreport]][goreport-url]
## Getting Started
`concur` is a Go library that allows you to safely and easily implement a concurrency pattern in your codebase. Install the latest version, and get up and running in minutes.
This library is currently used by the Five9-GO repository, to provide a reliable, safe way to interact with the Five9 API Websocket service.
### What is concurrency, and why is it useful?
```
Concurrency is the composition of independently executing computations.
Concurrency is a way to structure software, particularly as a way to write clean code that interacts well with the real world.
It is not parallelism.
- Rob Pike, 2012
```
Simply put, concurrency in software allows you to create **fast**, **robust** systems that can be relied upon to be **consistent**. Some examples of what concurrency can do, as provided by the Go team:
- [A Prime Number Sieve](https://go.dev/play/p/9U22NfrXeq)
- [An RSS Feed fetcher](https://cs.opensource.google/go/x/website/+/master:_content/talks/2013/advconc/realmain/realmain.go)
### Common pitfalls of concurrency that this library prevents
- Race conditions
- Deadlocks
- Unpredictable or "flaky" tests when testing concurrent data models (such as Websockets, which are inherently asynchronous messages being sent back and forth between systems)
### Install
```shell
go get github.com/equalsgibson/concur@v0.0.3
```
### Example of ASyncReader
Run the example ASyncReader with a mock asynchronous resource, along with a CPU and Memory profile.
https://github.com/equalsgibson/concur/blob/e3d8905e740043133e92e11918fd1c2e47d7e0e3/examples/async_reader_timer.go/main.go#L1-L109
Expected Output:
```bash
cgibson@wsl-ubuntuNexus:~/concur$ go run examples/async_reader_timer.go/main.go -cpuprofile cpu.prof -memprofile mem.prof
2024/10/29 00:01:00 Current Iteration: 1 - Current goroutines: 4
2024/10/29 00:01:01 Current Iteration: 2 - Current goroutines: 4
...
2024/10/29 00:01:03 Current Iteration: 299 - Current goroutines: 4
2024/10/29 00:01:03 Current Iteration: 300 - Current goroutines: 4
2024/10/29 00:01:05 Got an error response from Loop fetch function: end of the example - thanks for using the concur package
```
You can then analyze the profiles created, using the [pprof](https://pkg.go.dev/runtime/pprof#hdr-Profiling_a_Go_program) tool
## Contributing
Contributions are what make the open source community such an amazing place to learn, get inspired, and create. Any contributions you make are **greatly appreciated**.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!
1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request
## License
Distributed under the MIT License. See `LICENSE.txt` for more information.
## Contact
[Chris Gibson (@equalsgibson)](https://github.com/equalsgibson)
Project Link: [https://github.com/equalsgibson/concur](https://github.com/equalsgibson/concur)
## Acknowledgments
[golang]: https://img.shields.io/badge/v1.21-000?logo=go&logoColor=fff&labelColor=444&color=%2300ADD8
[golang-url]: https://go.dev/
[goref]: https://pkg.go.dev/badge/github.com/equalsgibson/concur.svg
[goref-url]: https://pkg.go.dev/github.com/equalsgibson/concur
[goreport]: https://goreportcard.com/badge/github.com/equalsgibson/concur
[goreport-url]: https://goreportcard.com/report/github.com/equalsgibson/concur