lib/celluloid/tasks/task_thread.rb in celluloid-0.13.0.pre vs lib/celluloid/tasks/task_thread.rb in celluloid-0.13.0.pre2

- old
+ new

@@ -6,10 +6,11 @@ # Run the given block within a task def initialize(type) super @resume_queue = Queue.new + @exception_queue = Queue.new @yield_mutex = Mutex.new @yield_cond = ConditionVariable.new actor = Thread.current[:celluloid_actor] mailbox = Thread.current[:celluloid_mailbox] @@ -17,12 +18,12 @@ raise NotActorError, "can't create tasks outside of actors" unless actor @thread = Celluloid.internal_pool.get do begin - ex = @resume_queue.pop.is_a?(Task::TerminatedError) - raise ex if ex + ex = @resume_queue.pop + raise ex if ex.is_a?(Task::TerminatedError) @status = :running Thread.current[:celluloid_actor] = actor Thread.current[:celluloid_mailbox] = mailbox Thread.current[:celluloid_task] = self @@ -30,10 +31,12 @@ actor.tasks << self yield rescue Task::TerminatedError # Task was explicitly terminated + rescue Exception => ex + @exception_queue << ex ensure @status = :dead actor.tasks.delete self @yield_cond.signal end @@ -57,9 +60,12 @@ raise DeadTaskError, "cannot resume a dead task" unless @thread.alive? @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 rescue ThreadError raise DeadTaskError, "cannot resume a dead task"