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 ⇒ 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.
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'ext/ilios/future.c', line 299 static VALUE future_await(VALUE self) { CassandraFuture *cassandra_future; GET_FUTURE(self, cassandra_future); if (cassandra_future->already_waited) { return self; } if (cassandra_future->on_success_block || cassandra_future->on_failure_block) { nogvl_sem_wait(&cassandra_future->sem); } else { nogvl_future_wait(cassandra_future->future); } cassandra_future->already_waited = true; return self; } |
#on_failure ⇒ Cassandra::Future
Run block when future resolves to error.
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'ext/ilios/future.c', line 254 static VALUE future_on_failure(VALUE self) { CassandraFuture *cassandra_future; bool wakeup_thread = false; 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"); } rb_mutex_lock(cassandra_future->proc_mutex); if (!cassandra_future->on_success_block) { // Invoke the callback with thread pool only once wakeup_thread = true; } cassandra_future->on_failure_block = rb_block_proc(); if (cass_future_ready(cassandra_future->future)) { rb_mutex_unlock(cassandra_future->proc_mutex); uv_sem_post(&cassandra_future->sem); if (cass_future_error_code(cassandra_future->future) != CASS_OK) { future_result_failure_yield(cassandra_future); } return self; } if (wakeup_thread) { future_queue_push(future_thread_pool_get(cassandra_future), self); } rb_mutex_unlock(cassandra_future->proc_mutex); return self; } |
#on_success {|value| ... } ⇒ Cassandra::Future
Run block when future resolves to a value.
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'ext/ilios/future.c', line 207 static VALUE future_on_success(VALUE self) { CassandraFuture *cassandra_future; bool wakeup_thread = false; 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"); } rb_mutex_lock(cassandra_future->proc_mutex); if (!cassandra_future->on_failure_block) { // Invoke the callback with thread pool only once wakeup_thread = true; } cassandra_future->on_success_block = rb_block_proc(); if (cass_future_ready(cassandra_future->future)) { rb_mutex_unlock(cassandra_future->proc_mutex); uv_sem_post(&cassandra_future->sem); if (cass_future_error_code(cassandra_future->future) == CASS_OK) { future_result_success_yield(cassandra_future); } return self; } if (wakeup_thread) { future_queue_push(future_thread_pool_get(cassandra_future), self); } rb_mutex_unlock(cassandra_future->proc_mutex); return self; } |