Skip to content

Instantly share code, notes, and snippets.

@ioquatix
Created June 30, 2020 12:54
Show Gist options
  • Save ioquatix/f918ee907a0107255c08a2aa93af5491 to your computer and use it in GitHub Desktop.
Save ioquatix/f918ee907a0107255c08a2aa93af5491 to your computer and use it in GitHub Desktop.
require 'thread/local'
class Searchable
extend Thread::Local
def initialize
@index = "rubygems"
end
def index(value)
@index = value
end
def lookup(query)
puts "execute #{query} on #{@index}"
end
end
def run_tests
Searchable.instance.lookup("hello world")
end
8.times.map do |index|
Thread.new do
# Before running tests:
searchable = Searchable.instance
# searchable.index "rubygems-#{index}"
run_tests
end
end.each(&:join)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment