Created
April 5, 2010 15:27
-
-
Save deepak/356462 to your computer and use it in GitHub Desktop.
do_msql does not block wholly
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 '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