Sha256: 824acb16336d206d3fe7b895d63a71fcf7a7a2488b1025ed129414bd174aa540
Contents?: true
Size: 1.06 KB
Versions: 1
Compression:
Stored size: 1.06 KB
Contents
module LitmusPaper module Dependency class TCP class EndpointAvailable < EM::Connection def initialize(fiber, timeout, ip, port) @fiber = fiber @ip = ip @port = port @timer = EM::Timer.new(timeout, method(:connection_timeout)) end def connection_completed close_connection @timer.cancel @fiber.resume(true) end def connection_timeout LitmusPaper.logger.info("Available check to #{@ip}:#{@port} failed with a timeout") @fiber.resume(false) end end def initialize(ip, port, options = {}) @ip, @port = ip, port @timeout = options.fetch(:timeout, 2) end def available? fiber = Fiber.current EM.connect(@ip, @port, EndpointAvailable, fiber, @timeout, @ip, @port) do |connection| connection.set_pending_connect_timeout @timeout end return Fiber.yield end def to_s "Dependency::TCP(tcp://#{@ip}:#{@port})" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
litmus_paper-0.2.2 | lib/litmus_paper/dependency/tcp.rb |