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:



331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'ext/ilios/future.c', line 331

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:



310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'ext/ilios/future.c', line 310

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:



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'ext/ilios/future.c', line 256

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);
}