Skip to content

Instantly share code, notes, and snippets.

@deepak
Created April 5, 2010 15:27
Show Gist options
  • Save deepak/356462 to your computer and use it in GitHub Desktop.
Save deepak/356462 to your computer and use it in GitHub Desktop.
do_msql does not block wholly
require 'rubygems'
require 'do_mysql'
# thanks to jeremyevans, he says:
# do_* drivers are async - uses rb_thread_select c-api call to manage
# threads.
# check if this code has been pushed upstream to the mysql library
# also see http://gist.github.com/356250 for plain mysql
thread1 = Thread.new {
while(true) do
print '*'
sleep 0.1
end
}
@connection = DataObjects::Connection.new("mysql://root:[email protected]/railsdb")
puts "=== stared blocking"
@reader = @connection.create_command('select sleep(20)').execute_reader
puts "=== created command"
@reader.next!
puts "=== finished blocking"
thread1.join
__END__
OUTPUT:
*=== stared blocking
*******************************************************************************************************************************************************************************************************=== created command
=== finished blocking
****************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment