Method: PGconn#async_exec

Defined in:
ext/pg.c

#async_exec(sql[, params, result_format ]) ⇒ PGresult #async_exec(sql[, params, result_format ]) {|pg_result| ... } ⇒ Object Also known as: async_query

This function has the same behavior as PGconn#exec, except that it’s implemented using asynchronous command processing and ruby’s rb_thread_select in order to allow other threads to process while waiting for the server to complete the request.

Overloads:

  • #async_exec(sql[, params, result_format ]) ⇒ PGresult

    Returns:

  • #async_exec(sql[, params, result_format ]) {|pg_result| ... } ⇒ Object

    Yields:

    • (pg_result)


2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
# File 'ext/pg.c', line 2660

static VALUE
pgconn_async_exec(int argc, VALUE *argv, VALUE self)
{
  VALUE rb_pgresult = Qnil;

  /* remove any remaining results from the queue */
  pgconn_get_last_result( self );

  pgconn_send_query( argc, argv, self );
  pgconn_block( 0, NULL, self );
  rb_pgresult = pgconn_get_last_result( self );

  if ( rb_block_given_p() ) {
    return rb_ensure( rb_yield, rb_pgresult, pgresult_clear, rb_pgresult );
  }
  return rb_pgresult;
}