Class: RbZMQ::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/rbzmq/context.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Context

Create new context.


12
13
14
# File 'lib/rbzmq/context.rb', line 12

def initialize(opts = {})
  @zmq_ctx = opts.delete(:context) { self.class.global }
end

Class Method Details

.globalZMQ::Context

Return a process global ZMQ context that will be lazy initialized on first request.


30
31
32
33
34
35
36
37
# File 'lib/rbzmq/context.rb', line 30

def global
  unless @zmq_ctx && @ctx_pid == Process.pid
    @zmq_ctx = ZMQ::Context.new
    @ctx_pid = Process.pid
  end

  @zmq_ctx
end

Instance Method Details

#pointerFFI::Pointer

Return `FFI::Pointer` from `ZMQ::Context`.


19
20
21
# File 'lib/rbzmq/context.rb', line 19

def pointer
  zmq_ctx.pointer
end