Go R1 Day 71

progress
- Learn Go With Tests -> Using
select
with channels to wait for multiple goroutines. - Of particular interest is this:
Notice how we have to use make when creating a channel; rather than say var ch chan struct{}. When you use var the variable will be initialised with the “zero” value of the type. So for string it is “”, int it is 0, etc. For channels the zero value is nil and if you try and send to it with <- it will block forever because you cannot send to nil channels select
- Used
httptest
to create mock server for faster testing, and included wrapper around a calls to allow configuration for timeout. This ensures that testing can handle in milliseconds, but default behavior in a deployment would be 10 seconds or more.
links
- select
- Go by Example: Select
- feat(11-select): 🎉 11-select initial framework without goroutines · sheldonhull/[email protected] · GitHub
- refactor(11-select): ♻️ refactor for DRY and better helper functions · sheldonhull/[email protected] · GitHub
- refactor(11-select): ♻️ add test case for error on timeout to avoid b… · sheldonhull/[email protected] · GitHub
- refactor(11-select): ♻️ refactor to allow configurable racer timeouts · sheldonhull/[email protected] · GitHub
Webmentions