https://github.com/karantan/go-concurrency
Examples of concurrent code in Go
https://github.com/karantan/go-concurrency
Last synced: about 2 months ago
JSON representation
Examples of concurrent code in Go
- Host: GitHub
- URL: https://github.com/karantan/go-concurrency
- Owner: karantan
- License: bsd-3-clause
- Created: 2021-08-10T08:33:41.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-03-18T11:48:01.000Z (about 3 years ago)
- Last Synced: 2025-02-13T15:53:54.479Z (4 months ago)
- Language: Go
- Size: 15.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-concurrency 
The goal of this project is to have a collection of concurrent code in Go. Because these
examples are small it's easier to understand the concepts they show. We can also check out
the code and play around with the examples to see how they behave under certain conditions.Because the examples are small it's also easy to test them, so in this repo, we will also
show how to test concurrent code in Go.If you have any feedback please consider raising a PR or creating a new issue.
## Usage
To see the output of the code you can take a look at the [GitHub actions](https://github.com/karantan/go-concurrency/actions),
click on a build and expand the Test section. You will see all the outputs for all
examples.If you want to play with the code locally you can git clone it and run tests in a debug
mode with Go plugin in Visual Studio Code editor. You will see the logs in the
terminal which will show you how the code runs.
The other way is to select an example function and run it in `main()` function in `main.go`
file and then run the main.go (`go run main.go`).`main.go` has a production working example of sending ssh commands to different servers.
It's used to execute commands via ssh concurrently on multuple servers at a time, saving
us a lot of time.To use it simply change the `serverHostnames := []string{"foo", "bar"}`.
In `async-workers/ssh.go` we define the "engine" for running ssh commands. It's basically
the same as the `production.go` version.## Additional reading
I highly recommend checking out [Learn Go with Test](https://quii.gitbook.io/learn-go-with-tests/)
and reading [Concurrency in Go](https://www.oreilly.com/library/view/concurrency-in-go/9781491941294/) book.