Sha256: 300a98c04f302deaf0f028ef2dc7aff4bac95d82cd39231d12f6087fad1ae32f
Contents?: true
Size: 1.11 KB
Versions: 3
Compression:
Stored size: 1.11 KB
Contents
module PsPabxListener class Main attr_reader :args, :listener attr_accessor :run def initialize *args @args = args.first @args[:timeout] ||= false @listener = PsPabxListener::Listener.new(@args[:host], @args[:user], @args[:password], @args[:timeout]) end # disconnects listener after given timeout is reached def get_data timeout, &block @listener.start start_time = Time.now runner = Thread.new do loop do @listener.get.each {|data| yield data} end end sleep 1 while Time.now - start_time < timeout runner.exit @listener.stop end # keeps getting data kind of forever and process the data def each_data &block @listener.start @run = true Signal.trap("INT") {@run = false} runner = Thread.new do loop do @listener.get.each {|data| yield data} end end sleep 1 while(@run) runner.exit @listener.stop end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
ps_pabx_listener-1.0.2 | lib/ps_pabx_listener/main.rb |
ps_pabx_listener-1.0.1 | lib/ps_pabx_listener/main.rb |
ps_pabx_listener-1.0.0 | lib/ps_pabx_listener/main.rb |