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 (go-fundamentals-select listed below)
- 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🔗
- go-fundamentals-select
- Go by Example: Select
- feat(11-select): 🎉 11-select initial framework without goroutines · sheldonhull/learn-go-with-tests-applied@b0a2641 · GitHub
- refactor(11-select): ♻️ refactor for DRY and better helper functions · sheldonhull/learn-go-with-tests-applied@1cf7092 · GitHub
- refactor(11-select): ♻️ add test case for error on timeout to avoid b… · sheldonhull/learn-go-with-tests-applied@77f01bd · GitHub
- refactor(11-select): ♻️ refactor to allow configurable racer timeouts · sheldonhull/learn-go-with-tests-applied@65fe79c · GitHub