JS Blog Software development, entertainment, lifestyle.


Goroutines don’t panic if channel they write to is gone


Couple of months ago I wrote an article about error handling in concurrent Go programs. One concern I had about it was if other goroutines would panic if some goroutine produces an error value which causes return from function when the channel is iterated with range construct. So I made another program that mimics scenario. It spawns couple of goroutines, each taking a second more to complete...

Error handling in concurrent programs in Golang


Error handling in concurrent programs in Go consists of little more work than if err != nil { return err } because the return value doesn’t reach intended receiver (for example in parent function where function was fired as a goroutine using go keyword). Just as we use channel for sending resulting data, we must also use channel for sending error. And we can do this using single channel of...

Testing concurrent code in Golang


I wrote a package which tracks certain hashtags on twitter and part of the package is adding and removing hashtag from list of hashtags. Plan is that this can be done from different goroutines hence tracking/untracking is done by putting hashtag in channels. It looks like this: var ( trackChan = make(chan string) untrackChan = make(chan string) ) func Track(hs ...string) { for _, h := range hs {...

JS Blog Software development, entertainment, lifestyle.

About me

Jernej Sila portrait
Hi, I'm Jernej, a software engineer from Slovenia. Welcome to my personal blog. For more about me, my work and hobbies, please visit my profile page.