<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -878,21 +878,27 @@ static VALUE io_socket( VALUE obj )
    }
 }
 
-/* async_query(sql, timeout=nil) */
-static VALUE async_query(int argc, VALUE* argv, VALUE obj)
-{
-    MYSQL* m = GetHandler(obj);   
 
-    VALUE sql, io, timeout, args[4];   
+/* schedule_without_timeout(sql) */
+static VALUE schedule_without_timeout( VALUE obj )
+{
+    MYSQL* m = GetHandler(obj);  
 
-    rb_scan_args(argc, argv, &quot;11&quot;, &amp;sql, &amp;timeout);
+    fd_set read;
 
-    if ( NIL_P( timeout ) ){
-      timeout = INT2NUM(m-&gt;net.read_timeout);
-    }
+    FD_ZERO(&amp;read);
+	FD_SET(m-&gt;net.fd, &amp;read);
 
-    send_query( obj, sql );
+    rb_thread_select(m-&gt;net.fd, &amp;read, NULL, NULL, NULL );
+}
 
+/* schedule_with_timeout(sql, timeout) */
+static VALUE schedule_with_timeout( VALUE obj, VALUE timeout )
+{
+    MYSQL* m = GetHandler(obj);  
+   
+    VALUE args[4];
+ 
     args[0] = rb_ary_new3(1, io_socket(obj) );
     args[1] = Qnil;
     args[2] = Qnil;
@@ -900,7 +906,23 @@ static VALUE async_query(int argc, VALUE* argv, VALUE obj)
 
     if ( rb_funcall2( id_io_klass, id_select, 4,  (VALUE *)args ) == Qnil ){
       mysql_raise(m);
-    } 
+    }
+}
+
+/* async_query(sql, timeout=nil) */
+static VALUE async_query(int argc, VALUE* argv, VALUE obj)
+{
+	VALUE sql, timeout;   
+
+    rb_scan_args(argc, argv, &quot;11&quot;, &amp;sql, &amp;timeout);
+
+    send_query( obj, sql );
+
+    if NIL_P( timeout ){
+      schedule_without_timeout( obj );
+    }else{
+      schedule_with_timeout( obj, timeout );
+    }
 
     return get_result( obj );
 }</diff>
      <filename>ext/mysql.c</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>fe11818218db8787cbb04be8045196f7d5c7459a</id>
    </parent>
  </parents>
  <author>
    <name>Lourens Naude</name>
    <email>lourens@methodmissing.com</email>
  </author>
  <url>http://github.com/methodmissing/mysqlplus/commit/94bad9d15e142f10fbe2f0f0350d11122f675f3e</url>
  <id>94bad9d15e142f10fbe2f0f0350d11122f675f3e</id>
  <committed-date>2008-09-01T11:37:17-07:00</committed-date>
  <authored-date>2008-09-01T11:37:17-07:00</authored-date>
  <message>Add schedule_without_timeout ( rb_thread_select based ) &amp;&amp; schedule_with_timeout ( IO.select based ) ... toggled by the presence of the timeout argument to Mysql.async_query</message>
  <tree>11a75422d8d926e514128c61f6298b172be7a7c5</tree>
  <committer>
    <name>Lourens Naude</name>
    <email>lourens@methodmissing.com</email>
  </committer>
</commit>
