…how to lock a piece of code so that it's guaranteed to only run once at a time. If it's running and another thread (or Goroutine in my case) reaches the same piece of code, it will wait for the first process to finish before continuing its execution.

I'm using it to lock an entire function, but apparently it works for any section of code.

Final thoughts

I love how everything is so straightforward in Go. The language itself forces you to write easy-to-understand code.

Latest on Go
Mastodon Mastodon