Class: Tanker::CTanker::CFuture

Inherits:
FFI::AutoPointer
  • Object
show all
Defined in:
lib/tanker/c_tanker/c_future.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr, proc = nil) ⇒ CFuture

Returns a new instance of CFuture.



15
16
17
18
# File 'lib/tanker/c_tanker/c_future.rb', line 15

def initialize(ptr, proc = nil, &)
  super
  @cfuture = ptr
end

Class Method Details

.release(ptr) ⇒ Object



20
21
22
# File 'lib/tanker/c_tanker/c_future.rb', line 20

def self.release(ptr)
  CTanker.tanker_future_destroy ptr
end

Instance Method Details

#getObject



24
25
26
27
28
29
30
31
32
# File 'lib/tanker/c_tanker/c_future.rb', line 24

def get
  CTanker.tanker_future_wait @cfuture
  if CTanker.tanker_future_has_error @cfuture
    cerr = CTanker.tanker_future_get_error @cfuture
    raise Error.from_ctanker_error(cerr)
  else
    CTanker.tanker_future_get_voidptr @cfuture
  end
end

#get_maybe_stringObject

rubocop:disable Naming/AccessorMethodName (this is not a getter)



41
42
43
44
45
46
47
48
49
50
# File 'lib/tanker/c_tanker/c_future.rb', line 41

def get_maybe_string # rubocop:disable Naming/AccessorMethodName (this is not a getter)
  str_ptr = get
  if str_ptr.null?
    nil
  else
    str = str_ptr.get_string(0).force_encoding(Encoding::UTF_8)
    CTanker.tanker_free_buffer str_ptr
    str
  end
end

#get_stringObject

rubocop:disable Naming/AccessorMethodName (this is not a getter)



34
35
36
37
38
39
# File 'lib/tanker/c_tanker/c_future.rb', line 34

def get_string # rubocop:disable Naming/AccessorMethodName (this is not a getter)
  str_ptr = get
  str = str_ptr.get_string(0).force_encoding(Encoding::UTF_8)
  CTanker.tanker_free_buffer str_ptr
  str
end