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:



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

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:



290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'ext/ilios/future.c', line 290

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:



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'ext/ilios/future.c', line 238

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