Class: Ilios::Cassandra::Future
- Inherits:
-
Object
- Object
- Ilios::Cassandra::Future
- Defined in:
- ext/ilios/ilios.c
Instance Method Summary collapse
-
#await ⇒ Cassandra::Future
Wait to complete a future's statement.
-
#on_failure {|error| ... } ⇒ Cassandra::Future
Run block when future resolves to error.
-
#on_success {|value| ... } ⇒ Cassandra::Future
Run block when future resolves to a value.
Instance Method Details
#await ⇒ Cassandra::Future
Wait to complete a future's statement.
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
# File 'ext/ilios/future.c', line 354 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_failure {|error| ... } ⇒ Cassandra::Future
Run block when future resolves to error.
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
# File 'ext/ilios/future.c', line 333 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.
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'ext/ilios/future.c', line 273 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); } |