class FDB::Future
Public Class Methods
finalize(ptr)
click to toggle source
# File lib/fdbimpl.rb, line 302 def self.finalize(ptr) proc do #puts "Destroying future #{ptr}" FDBC.fdb_future_destroy(ptr) end end
new(fpointer)
click to toggle source
# File lib/fdbimpl.rb, line 309 def initialize(fpointer) @fpointer = fpointer ObjectSpace.define_finalizer(self, FDB::Future.finalize(@fpointer)) end
wait_for_any(*futures)
click to toggle source
# File lib/fdbimpl.rb, line 358 def self.wait_for_any(*futures) if futures.empty? raise ArgumentError, "wait_for_any requires at least one future" end mx = Mutex.new cv = ConditionVariable.new ready_idx = -1 futures.each_with_index do |f, i| f.on_ready do |f| mx.synchronize { if ready_idx < 0 ready_idx = i cv.signal end } end end mx.synchronize { if ready_idx < 0 cv.wait mx end } ready_idx end
Public Instance Methods
block_until_ready()
click to toggle source
# File lib/fdbimpl.rb, line 322 def block_until_ready FDBC.check_error FDBC.fdb_future_block_until_ready(@fpointer) end
callback_wrapper(f) { |f| ... }
click to toggle source
# File lib/fdbimpl.rb, line 327 def callback_wrapper(f, &block) begin yield f rescue Exception begin $stderr.puts "Discarding uncaught exception from user callback:" $stderr.puts "#{$@.first}: #{$!.message} (#{$!.class})", $@.drop(1).map{|s| "\t#{s}"} rescue Exception end end end
cancel()
click to toggle source
# File lib/fdbimpl.rb, line 314 def cancel FDBC.fdb_future_cancel(@fpointer) end
on_ready(&block)
click to toggle source
# File lib/fdbimpl.rb, line 326 def on_ready(&block) def callback_wrapper(f, &block) begin yield f rescue Exception begin $stderr.puts "Discarding uncaught exception from user callback:" $stderr.puts "#{$@.first}: #{$!.message} (#{$!.class})", $@.drop(1).map{|s| "\t#{s}"} rescue Exception end end end entry = CallbackEntry.new FDB.cb_mutex.synchronize { pos = FDB.ffi_callbacks.length entry.index = pos FDB.ffi_callbacks << entry } entry.callback = FFI::Function.new(:void, [:pointer, :pointer]) do |ign1, ign2| FDB.cb_mutex.synchronize { FDB.ffi_callbacks[-1].index = entry.index FDB.ffi_callbacks[entry.index] = FDB.ffi_callbacks[-1] FDB.ffi_callbacks.pop } callback_wrapper(self, &block) end FDBC.fdb_future_set_callback(@fpointer, entry.callback, nil) end
ready?()
click to toggle source
# File lib/fdbimpl.rb, line 318 def ready? return !FDBC.fdb_future_is_ready(@fpointer).zero? end
Private Instance Methods
release_memory()
click to toggle source
# File lib/fdbimpl.rb, line 390 def release_memory FDBC.fdb_future_release_memory(@fpointer) end