Sha256: c60b37d27f265b789a0b2d24fa88bbf9bb98845b6b957f257e52b0cb584dd62d

Contents?: true

Size: 1.5 KB

Versions: 6

Compression:

Stored size: 1.5 KB

Contents

module Celluloid
  class Task
    # Tasks with a Fiber backend
    class Fibered < Task
      class StackError < Celluloid::Error; end
      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
          # TODO: Determine why infinite thread leakage happens under jRuby, if `Fiber.yield` is used:
          Fiber.yield unless RUBY_PLATFORM == "java"
        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 StackError, "#{ex} @#{meta[:method_name] || :unknown} (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::Task::Threaded` if you need backtraces here."]
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
celluloid-0.17.4 lib/celluloid/task/fibered.rb
celluloid-0.17.3 lib/celluloid/task/fibered.rb
celluloid-0.17.2 lib/celluloid/task/fibered.rb
celluloid-0.17.1.2 lib/celluloid/task/fibered.rb
celluloid-0.17.1.1 lib/celluloid/task/fibered.rb
celluloid-0.17.1 lib/celluloid/task/fibered.rb