lib/tork/server.rb in tork-16.0.0 vs lib/tork/server.rb in tork-17.0.0
- old
+ new
@@ -1,32 +1,26 @@
-require 'json'
+require 'tork/client'
module Tork
module Server
def quit
- throw :tork_server_quit
+ Thread.exit # kill Client::Receiver in loop()
end
def loop
- (@client = STDOUT.dup).sync = true
+ @client = Client::Transmitter.new(STDOUT.dup)
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
+ 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
+ end.join
rescue Interrupt
# forced quit
end
def self.extended server