JS Blog Software development, entertainment, lifestyle.

Tagchannels

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

G

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

E

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

T

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 {...

Channels in Go

C

Do not communicate by sharing memory; instead, share memory by communicating. Channels are for orchestration, mutexes are for serialization. Go Proverbs – Rob Pike Yesterday I wrote my first project ((It’s URL shorterer, a project which I write in every new programming language I learn.)) in Go which does not use traditional locks when dealing with shared data in concurrent programs...

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.

Categories

Archives