Skip to content

Instantly share code, notes, and snippets.

@fxposter
Created October 24, 2019 11:09
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 fxposter/205a6ec18f3f302ce9f2dd25d790e249 to your computer and use it in GitHub Desktop.
Save fxposter/205a6ec18f3f302ce9f2dd25d790e249 to your computer and use it in GitHub Desktop.
require 'thread'
class Test
def initialize(queue)
@queue = queue
end
def run
value = nil
while value = @queue.pop
Thread.new {
update(value)
}
end
end
def update(x)
sleep 1
p x
end
end
queue = Queue.new
Thread.new {
queue << { 'hello' => 'world' }
queue << { 'hello2' => 'world2' }
queue << nil
}
Test.new(queue).run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment