Skip to content

Commit 102d4e1

Browse files
committed
Reduce the time spent waiting for output
1 parent 9bf7fda commit 102d4e1

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/process_executer/monitored_pipe.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def close
8686
return unless state == :open
8787

8888
@state = :closing
89-
sleep 0.01 until state == :closed
89+
sleep 0.001 until state == :closed
9090
end
9191

9292
# Return the write end of the pipe so that data can be written to it
@@ -149,6 +149,8 @@ def fileno
149149
# @api private
150150
#
151151
def write(data)
152+
raise IOError, 'closed stream' unless state == :open
153+
152154
pipe_writer.write(data)
153155
end
154156

@@ -289,7 +291,7 @@ def monitor_pipe
289291
@state = :closing
290292
end
291293
rescue IO::WaitReadable
292-
pipe_reader.wait_readable(0.01)
294+
pipe_reader.wait_readable(0.001)
293295
end
294296

295297
# Read any remaining data from the pipe and close it

spec/process_executer/monitored_pipe_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,12 @@
166166
expect { monitored_pipe.write('world') }.to raise_error(IOError, 'closed stream')
167167
end
168168
end
169+
170+
context 'after the pipe is closed' do
171+
it 'should raise an exception' do
172+
monitored_pipe.close
173+
expect { monitored_pipe.write('hello') }.to raise_error(IOError, 'closed stream')
174+
end
175+
end
169176
end
170177
end

0 commit comments

Comments
 (0)