Class: Julewire::Core::Destinations::SynchronizedOutput
- Inherits:
-
Object
- Object
- Julewire::Core::Destinations::SynchronizedOutput
- Defined in:
- lib/julewire/core/destinations/synchronized_output.rb
Instance Method Summary collapse
- #after_fork! ⇒ Object
- #close ⇒ Object
- #flush ⇒ Object
-
#initialize(output, close_output: false) ⇒ SynchronizedOutput
constructor
A new instance of SynchronizedOutput.
- #output_class_name ⇒ Object
- #resource_identity ⇒ Object
- #write(value) ⇒ Object
Constructor Details
#initialize(output, close_output: false) ⇒ SynchronizedOutput
Returns a new instance of SynchronizedOutput.
7 8 9 10 11 12 |
# File 'lib/julewire/core/destinations/synchronized_output.rb', line 7 def initialize(output, close_output: false) Sink.validate_writeable!(output) @output = output @close_output = close_output @mutex = Mutex.new end |
Instance Method Details
#after_fork! ⇒ Object
14 15 16 17 18 |
# File 'lib/julewire/core/destinations/synchronized_output.rb', line 14 def after_fork! @mutex = Mutex.new @output.after_fork! if @output.respond_to?(:after_fork!) self end |
#close ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/julewire/core/destinations/synchronized_output.rb', line 36 def close @mutex.synchronize do return true if output_closed? result = if @close_output && @output.respond_to?(:close) @output.close elsif @output.respond_to?(:flush) @output.flush end result != false end end |
#flush ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/julewire/core/destinations/synchronized_output.rb', line 28 def flush @mutex.synchronize do return true unless @output.respond_to?(:flush) @output.flush != false end end |
#output_class_name ⇒ Object
20 |
# File 'lib/julewire/core/destinations/synchronized_output.rb', line 20 def output_class_name = @output.class.name |
#resource_identity ⇒ Object
22 |
# File 'lib/julewire/core/destinations/synchronized_output.rb', line 22 def resource_identity = @output |
#write(value) ⇒ Object
24 25 26 |
# File 'lib/julewire/core/destinations/synchronized_output.rb', line 24 def write(value) @mutex.synchronize { @output.write(value) } end |