Parent

Class/Module Index [+]

Quicksearch

Celluloid::Task

Tasks are interruptable/resumable execution contexts used to run methods

Attributes

status[R]
type[R]

Public Class Methods

current() click to toggle source

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
new(type) click to toggle source

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
suspend(status) click to toggle source

Suspend the running task, deferring to the scheduler

# File lib/celluloid/tasks.rb, line 18
def self.suspend(status)
  Task.current.suspend(status)
end

Public Instance Methods

backtrace() click to toggle source
# File lib/celluloid/tasks.rb, line 78
def backtrace
end
create(&block) click to toggle source
# File lib/celluloid/tasks.rb, line 52
def create(&block)
  raise "Implement #{self.class}#create"
end
inspect() click to toggle source

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(value = nil) click to toggle source

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
running?() click to toggle source

Is the current task still running?

# File lib/celluloid/tasks.rb, line 82
def running?; @status != :dead; end
suspend(status) click to toggle source

Suspend the current task, changing the status to the given argument

# File lib/celluloid/tasks.rb, line 57
def suspend(status)
  @status = status
  value = signal

  raise value if value.is_a?(Task::TerminatedError)
  @status = :running

  value
end
terminate() click to toggle source

Terminate this task

# File lib/celluloid/tasks.rb, line 74
def terminate
  resume Task::TerminatedError.new("task was terminated") if running?
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.