Advertisement
Guest User

Untitled

a guest
Aug 25th, 2023
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.47 KB | None | 0 0
  1. r1 = Ractor.new do
  2.   1.upto(10) do |i|
  3.     sleep(0.2)
  4.     Ractor.yield i
  5.   end
  6. end
  7.  
  8. r2 = Ractor.new do
  9.   11.upto(15) do |i|
  10.     sleep(0.2)
  11.     Ractor.yield i
  12.   end
  13. end
  14.  
  15. loop do
  16.   _, obj = Ractor.select(r1, r2)
  17.   puts obj
  18. end
  19.  
  20.  
  21. Here is output:
  22. > ruby ractor_play.rb
  23. ractor_play.rb:1: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues.
  24. 11
  25. 1
  26. 12
  27. 2
  28. 13
  29. 3
  30. 14
  31. 4
  32. 5
  33. 15
  34. 11
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement