Created
October 24, 2019 11:09
-
-
Save fxposter/205a6ec18f3f302ce9f2dd25d790e249 to your computer and use it in GitHub Desktop.
This file contains 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' | |
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