Task

Using either native language concurrency syntax or freely available libraries, write a program to display the strings "Enjoy" "Rosetta" "Code", one string per line, in random order.

Concurrency syntax must use threads, tasks, co-routines, or whatever concurrency is called in your language.




require "channel"
require "fiber"
require "random"
 
done = Channel(Nil).new
 
"Enjoy Rosetta Code".split.map do |x|
  spawn do
    sleep Random.new.rand(0..500).milliseconds
    puts x
    done.send nil
  end
end
 
3.times do
  done.receive
end