Skip to content

Commit

Permalink
Allow TaskThread to raise exceptions outside
Browse files Browse the repository at this point in the history
  • Loading branch information
halorgium committed Mar 15, 2013
1 parent 5e5bba6 commit 91905bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/celluloid/tasks/task_thread.rb
Expand Up @@ -8,6 +8,7 @@ def initialize(type)
super

@resume_queue = Queue.new
@exception_queue = Queue.new
@yield_mutex = Mutex.new
@yield_cond = ConditionVariable.new

Expand All @@ -32,6 +33,8 @@ def initialize(type)
yield
rescue Task::TerminatedError
# Task was explicitly terminated
rescue Exception => ex
@exception_queue << ex
ensure
@status = :dead
actor.tasks.delete self
Expand Down Expand Up @@ -59,6 +62,9 @@ def resume(value = nil)
@yield_mutex.synchronize do
@resume_queue.push(value)
@yield_cond.wait(@yield_mutex)
while @exception_queue.size > 0
raise @exception_queue.pop
end
end

nil
Expand Down
9 changes: 9 additions & 0 deletions spec/support/task_examples.rb
Expand Up @@ -33,4 +33,13 @@ def initialize
subject.should_not be_running
end

it "raises exceptions outside" do
task = task_class.new(task_type) do
raise "failure"
end
expect do
task.resume
end.to raise_exception("failure")
end

end

0 comments on commit 91905bd

Please sign in to comment.