Created
November 6, 2017 19:38
-
-
Save alexandru-calinoiu/36c538ffc4695bbbaf5648f5e504adb4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'thread' | |
q = Queue.new | |
eq = Enumerator.new(-> { q.size }) do |y| | |
loop do | |
y << q.pop | |
end | |
end | |
doubler = Thread.new do | |
eq.each do |n| | |
break if n == :stop | |
p n * n | |
end | |
end | |
q << 1 | |
q << 2 | |
q << 4 | |
p eq.size | |
q << :stop | |
doubler.join |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment