Sha256: c6ae775e35213828c7f3b1326b5e4b07cb7ea1cfe9a483c809b931f7be5fe8b7
Contents?: true
Size: 1.77 KB
Versions: 1
Compression:
Stored size: 1.77 KB
Contents
require 'stringio' class ThreadOut def initialize(out) @out = out end def write(stuff='') if Thread.current[:stdout] then Thread.current[:stdout].write stuff else @out.write stuff end end def puts(stuff='') if Thread.current[:stdout] then Thread.current[:stdout].puts stuff else @out.puts stuff end end def print(stuff='') if Thread.current[:stdout] then Thread.current[:stdout].puts stuff else @out.print stuff end end def flush if Thread.current[:stdout] then Thread.current[:stdout].flush else @out.flush end end end STDOUT.sync = true STDERR.sync = true $stdout = ThreadOut.new(STDOUT) $stderr = ThreadOut.new(STDERR) class SyncOut def self.mutex @@mutex ||= Mutex.new end def self.flushOutput mutex.synchronize do tmp = Thread.current[:stdout] if tmp.string.length > 0 Thread.current[:stdout] = Thread.current[:tmpStdout] puts tmp.string tmp.reopen("") Thread.current[:stdout] = tmp end end end def self.startStream s = StringIO.new Thread.current[:tmpStdout] = Thread.current[:stdout] Thread.current[:stdout] = s end def self.stopStream(result) s = Thread.current[:stdout] Thread.current[:stdout] = Thread.current[:tmpStdout] if s.string.length > 0 mutex.synchronize do if !result && Bake.options.stopOnFirstError @@errors << s.string else puts s.string end end end end def self.flush_errors puts @@errors unless @@errors.empty? reset_errors end def self.reset_errors @@errors = "" end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
bake-toolkit-2.33.0 | lib/common/ext/stdout.rb |