The Crystal Programming Language Forum

What is `select` re concurrency?

The blog post announcing parallelism mentions select as a concurrency statement, and the release notes for 0.33.0 do too.

I’ve tried to find documentation about said select in the reference guide or docs without luck (perhaps I missed it?). Fiber#select seems like a candidate, but has no docs.

Can anyone give a crash course about it?

It’s derived from Go, best bet would be checking out their docs for the moment.

I see! Which would be the equivalent syntax for

select {
case msg1 := <-c1:
    fmt.Println("received", msg1)
case msg2 := <-c2:
    fmt.Println("received", msg2)


Probably something like

when msg1 = ch1.receive
  puts "received #{msg1}"
when msg2 = ch2.receive
  puts "received #{msg2}"
1 Like

We have some documentation material planned to give better visibility to the select, but for now can help to understand the different options.


Yeah with the changes related to timeout I think we can assume the API is stable enough to write the documentation.

@fxn I’ve been thinking about writing this article since I read your post. It’s finally out!

@lbarasti thanks a lot for the post, and also thanks a lot for following up here :heart:.