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

- old
+ new

@@ -1,32 +1,36 @@ module Celluloid # Tasks with a Thread backend - class TaskThread + class TaskThread < Task attr_reader :type, :status # Run the given block within a task def initialize(type) - @type = type - @status = :new + super @resume_queue = Queue.new @yield_mutex = Mutex.new @yield_cond = ConditionVariable.new - actor, mailbox = Thread.current[:actor], Thread.current[:mailbox] + actor = Thread.current[:celluloid_actor] + mailbox = Thread.current[:celluloid_mailbox] + chain_id = Thread.current[:celluloid_chain_id] + raise NotActorError, "can't create tasks outside of actors" unless actor - @thread = InternalPool.get do + @thread = Celluloid.internal_pool.get do begin - unless @resume_queue.pop.is_a?(Task::TerminatedError) - @status = :running - Thread.current[:actor] = actor - Thread.current[:mailbox] = mailbox - Thread.current[:task] = self - actor.tasks << self + ex = @resume_queue.pop.is_a?(Task::TerminatedError) + raise ex if ex - yield - end + @status = :running + Thread.current[:celluloid_actor] = actor + Thread.current[:celluloid_mailbox] = mailbox + Thread.current[:celluloid_task] = self + Thread.current[:celluloid_chain_id] = chain_id + + actor.tasks << self + yield rescue Task::TerminatedError # Task was explicitly terminated ensure @status = :dead actor.tasks.delete self