Permalink
Browse files

Clarify Forker#result

  • Loading branch information...
1 parent 5b550b3 commit becc3e4348c524af79e22ee554511b46e83686f9 @timcharper timcharper committed Mar 16, 2012
Showing with 10 additions and 4 deletions.
  1. +4 −3 lib/spork/forker.rb
  2. +6 −1 spec/spork/forker_spec.rb
View
7 lib/spork/forker.rb
@@ -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
View
7 spec/spork/forker_spec.rb
@@ -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

0 comments on commit becc3e4

Please sign in to comment.