Sha256: 5e4cf0c1fcbd627586da4344d5d5ec72a82071ff89dd3639adfdd9ab2b395add

Contents?: true

Size: 650 Bytes

Versions: 5

Compression:

Stored size: 650 Bytes

Contents

module BoomNats
  module Requester
    def request(topic, params = nil, options = {})
      result = nil
      BoomNats.application.execute do |nats|
        timeout = Concurrent::Cancellation.timeout 5
        done = Concurrent::Channel.new(capacity: 1)
        Concurrent::Channel.go do
          nats.request(topic, params.to_json, options) do |msg|
            done << JSON.parse(msg)
          end
          timeout.origin.wait
          done << BoomNats::Error.new("request do not received")
        end
        result = ~done # block until signaled
      end
      raise result if result.is_a?(BoomNats::Error)

      result
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
boom_nats-0.1.5 lib/boom_nats/requester.rb
boom_nats-0.1.4 lib/boom_nats/requester.rb
boom_nats-0.1.3 lib/boom_nats/requester.rb
boom_nats-0.1.2 lib/boom_nats/requester.rb
boom_nats-0.1.1 lib/boom_nats/requester.rb