Class: Ilios::Cassandra::Future

Inherits:
Object
  • Object
show all
Defined in:
ext/ilios/ilios.c

Instance Method Summary collapse

Instance Method Details

#awaitCassandra::Future

Wait to complete a future's statement.

Returns:



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# File 'ext/ilios/future.c', line 336

static VALUE future_await(VALUE self)
{
    CassandraFuture *cassandra_future;

    GET_FUTURE(self, cassandra_future);

    rb_mutex_lock(cassandra_future->proc_mutex);
    if (cassandra_future->already_waited) {
        rb_mutex_unlock(cassandra_future->proc_mutex);
        return self;
    }
    cassandra_future->already_waited = true;
    rb_mutex_unlock(cassandra_future->proc_mutex);

    nogvl_future_wait(cassandra_future->future);
    if (cassandra_future->on_success_block || cassandra_future->on_failure_block) {
        nogvl_sem_wait(&cassandra_future->sem);
    }
    return self;
}

#on_failureCassandra::Future

Run block when future resolves to error.

Returns:

Raises:



315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'ext/ilios/future.c', line 315

static VALUE future_on_failure(VALUE self)
{
    CassandraFuture *cassandra_future;

    GET_FUTURE(self, cassandra_future);

    if (cassandra_future->on_failure_block) {
        rb_raise(eExecutionError, "It should not call twice");
    }
    if (!rb_block_given_p()) {
        rb_raise(rb_eArgError, "no block given");
    }

    return rb_mutex_synchronize(cassandra_future->proc_mutex, future_on_failure_synchronize, self);
}

#on_success {|value| ... } ⇒ Cassandra::Future

Run block when future resolves to a value.

Yield Parameters:

  • value (Cassandra::Statement, Cassandra::Result)

    A value. Yields Cassandra::Statement object when future was created by Cassandra::Session#prepare_async. Yields Cassandra::Result object when future was created by Cassandra::Session#execute_async.

Returns:

Raises:



261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'ext/ilios/future.c', line 261

static VALUE future_on_success(VALUE self)
{
    CassandraFuture *cassandra_future;

    GET_FUTURE(self, cassandra_future);

    if (cassandra_future->on_success_block) {
        rb_raise(eExecutionError, "It should not call twice");
    }
    if (!rb_block_given_p()) {
        rb_raise(rb_eArgError, "no block given");
    }

    return rb_mutex_synchronize(cassandra_future->proc_mutex, future_on_success_synchronize, self);
}