Skip to content

Instantly share code, notes, and snippets.

@thedarkone
Created November 12, 2014 10:37
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 thedarkone/d1c26e08f7eca3bc224e to your computer and use it in GitHub Desktop.
Save thedarkone/d1c26e08f7eca3bc224e to your computer and use it in GitHub Desktop.
class Foo
puts "defining Foo::Bar"
class Bar
sleep 5
end
puts "done defining Foo::Bar"
end
class Foo
autoload :Bar, 'bar.rb'
end
a = Thread.new do
puts "A accessing const"
Foo::Bar # should sleep for 5 seconds
puts "A finished with const"
end
b = Thread.new do
sleep 2
if defined?(Foo::Bar)
puts "B accessing const"
Foo::Bar # should return immediately, before A has finished
puts "B finished with const"
else
puts "B sees Foo::Bar not defined yet"
end
end
[a,b].each(&:join)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment