Sha256: 4f1afaedd79aaffbe4e167f5ca95e2ae8323d0cadbd2b074415871f27024cadd

Contents?: true

Size: 725 Bytes

Versions: 4

Compression:

Stored size: 725 Bytes

Contents

require 'json'

module Tork
module Server

  def quit
    throw :tork_server_quit
  end

  def loop
    (@client = STDOUT.dup).sync = true
    STDOUT.reopen(STDERR).sync = true

    catch :tork_server_quit do
      while line = STDIN.gets
        warn "#{caller[2]} RECV #{line.chomp}" if $DEBUG

        command = JSON.load(line)
        method = command.first

        if respond_to? method and method != __method__ # prevent loops
          @command, @command_line = command, line
          __send__(*command)
        else
          warn "#{self}: bad command: #{method}"
        end
      end
    end
  rescue Interrupt
    # forced quit
  end

  def self.extended server
    trap(:SIGTERM){ server.quit }
  end

end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tork-16.0.0 lib/tork/server.rb
tork-15.1.0 lib/tork/server.rb
tork-15.0.1 lib/tork/server.rb
tork-15.0.0 lib/tork/server.rb