Sha256: b00a0aef492105df654dd124013f0e513a1f41f0d7ea8449db553478db15242a

Contents?: true

Size: 1.24 KB

Versions: 8

Compression:

Stored size: 1.24 KB

Contents

module Celluloid
  class FiberStackError < Celluloid::Error; end

  # Tasks with a Fiber backend
  class TaskFiber < Task

    def create
      queue = Thread.current[:celluloid_queue]
      actor_system = Thread.current[:celluloid_actor_system]
      @fiber = Fiber.new do
        # FIXME: cannot use the writer as specs run inside normal Threads
        Thread.current[:celluloid_role] = :actor
        Thread.current[:celluloid_queue] = queue
        Thread.current[:celluloid_actor_system] = actor_system
        yield
      end
    end

    def signal
      Fiber.yield
    end

    # Resume a suspended task, giving it a value to return if needed
    def deliver(value)
      @fiber.resume value
    rescue SystemStackError => ex
      raise FiberStackError, "#{ex} (please see https://github.com/celluloid/celluloid/wiki/Fiber-stack-errors)"
    rescue FiberError => ex
      raise DeadTaskError, "cannot resume a dead task (#{ex})"
    end

    # Terminate this task
    def terminate
      super
    rescue FiberError
      # If we're getting this the task should already be dead
    end

    def backtrace
      ["#{self.class} backtrace unavailable. Please try `Celluloid.task_class = Celluloid::TaskThread` if you need backtraces here."]
    end
  end
end

Version data entries

8 entries across 6 versions & 4 rubygems

Version Path
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/celluloid-0.16.0/lib/celluloid/tasks/task_fiber.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/celluloid-0.16.0/lib/celluloid/tasks/task_fiber.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/celluloid-0.16.0/lib/celluloid/tasks/task_fiber.rb
scoot-0.0.4 .bundle/gems/ruby/2.2.0/gems/celluloid-0.16.0/lib/celluloid/tasks/task_fiber.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/celluloid-0.16.0/lib/celluloid/tasks/task_fiber.rb
celluloid-0.16.0 lib/celluloid/tasks/task_fiber.rb
celluloid-0.16.0.pre3 lib/celluloid/tasks/task_fiber.rb
celluloid-0.16.0.pre2 lib/celluloid/tasks/task_fiber.rb