Sha256: 0992a4bbd7eb3c4a1ba5f6ea2e0e6a7c9bb1f7ec51147145c116a1965bb81771

Contents?: true

Size: 631 Bytes

Versions: 6

Compression:

Stored size: 631 Bytes

Contents

require 'tork/client'

module Tork
class Server

  def initialize
    trap(:SIGTERM){ quit }
  end

  def quit
    Thread.exit # kill Client::Receiver in loop()
  end

  def loop
    @client = Client::Transmitter.new(STDOUT.dup)
    STDOUT.reopen(STDERR).sync = true

    Client::Receiver.new(STDIN) do |command|
      method = command.first
      if respond_to? method and method != __method__ # prevent loops
        @command = command
        __send__(*command)
      else
        warn "#{self}: invalid command: #{method}"
      end
    end.join
  rescue Interrupt
    # forced quit
  ensure
    Process.waitall
  end

end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
tork-18.2.2 lib/tork/server.rb
tork-18.2.1 lib/tork/server.rb
tork-18.2.0 lib/tork/server.rb
tork-18.1.0 lib/tork/server.rb
tork-18.0.1 lib/tork/server.rb
tork-18.0.0 lib/tork/server.rb