Object
Tasks are interruptable/resumable execution contexts used to run methods
Obtain the current task
# File lib/celluloid/tasks.rb, line 13 def self.current Thread.current[:celluloid_task] or raise NotTaskError, "not within a task context" end
Create a new task
# File lib/celluloid/tasks.rb, line 25 def initialize(type) @type = type @status = :new actor = Thread.current[:celluloid_actor] chain_id = Thread.current[:celluloid_chain_id] raise NotActorError, "can't create tasks outside of actors" unless actor create do begin @status = :running actor.setup_thread 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 end end end
# File lib/celluloid/tasks.rb, line 52 def create(&block) raise "Implement #{self.class}#create" end
Nicer string inspect for tasks
# File lib/celluloid/tasks.rb, line 85 def inspect "#<#{self.class}:0x#{object_id.to_s(16)} @type=#{@type.inspect}, @status=#{@status.inspect}>" end
Resume a suspended task, giving it a value to return if needed
# File lib/celluloid/tasks.rb, line 68 def resume(value = nil) deliver(value) nil end
Is the current task still running?
# File lib/celluloid/tasks.rb, line 82 def running?; @status != :dead; end
Generated with the Darkfish Rdoc Generator 2.