Skip to content

Commit

Permalink
Clarify Forker#result
Browse files Browse the repository at this point in the history
  • Loading branch information
timcharper committed Mar 16, 2012
1 parent 5b550b3 commit becc3e4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/spork/forker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@ def initialize(&block)
#
# If the fork was aborted, then result returns nil.
def result
return unless running?
return @result if defined?(@result) || ! running?
result_thread = Thread.new do
begin
@result = Marshal.load(@server_io)
Marshal.dump('ACK', @server_io)
rescue ForkDiedException, EOFError
rescue EOFError
@result = nil
rescue ForkDiedException
end
end
Process.wait(@child_pid)
result_thread.raise(ForkDiedException) if @result.nil?
result_thread.raise(ForkDiedException) if result_thread.status == "sleep"
@child_pid = nil
@result
end
Expand Down
7 changes: 6 additions & 1 deletion spec/spork/forker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
it "aborts a fork and returns nil for the result" do
started_at = Time.now
ended_at = nil
forker = Spork::Forker.new { sleep 5 }
forker = Spork::Forker.new do
begin
sleep 5
rescue SignalException
end
end
Thread.new do
forker.result.should == nil
ended_at = Time.now
Expand Down

0 comments on commit becc3e4

Please sign in to comment.