Skip to content

Instantly share code, notes, and snippets.

@alexandru-calinoiu
Created November 6, 2017 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexandru-calinoiu/36c538ffc4695bbbaf5648f5e504adb4 to your computer and use it in GitHub Desktop.
Save alexandru-calinoiu/36c538ffc4695bbbaf5648f5e504adb4 to your computer and use it in GitHub Desktop.
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