lib/pigato/client.rb in pigato-0.2.0 vs lib/pigato/client.rb in pigato-0.2.1

- old
+ new

@@ -1,20 +1,30 @@ require "oj" require "securerandom" class Pigato::Client - def initialize broker + def initialize broker, conf = {} @broker = broker @context = ZMQ::Context.new(1) @socket = nil @poller = ZMQ::Poller.new - @timeout = 2500 - start + @conf = { + :autostart => false, + :timeout => 2500 + } + + @conf.merge!(conf) + + if @conf[:autostart] + start + end end - def request service, request, timeout = @timeout + def request service, request, timeout = @conf[:timeout] + return nil if @socket == nil; + request = [Oj.dump(request)] rid = SecureRandom.uuid request = [Pigato::C_CLIENT, Pigato::W_REQUEST, service, rid].concat(request) @socket.send_strings request