Class: Celluloid::Task::Fibered

Inherits:
Celluloid::Task show all
Defined in:
lib/celluloid/task/fibered.rb

Overview

Tasks with a Fiber backend

Defined Under Namespace

Classes: StackError

Instance Attribute Summary

Attributes inherited from Celluloid::Task

#chain_id, #guard_warnings, #meta, #status, #type

Instance Method Summary collapse

Methods inherited from Celluloid::Task

current, #exclusive, #exclusive?, #guard, #initialize, #inspect, #resume, #running?, #suspend, suspend

Constructor Details

This class inherits a constructor from Celluloid::Task

Instance Method Details

#backtraceObject



42
43
44
45
46
# File 'lib/celluloid/task/fibered.rb', line 42

def backtrace
  # rubocop:disable Metrics/LineLength
  ["#{self.class} backtrace unavailable. Please try `Celluloid.task_class = Celluloid::Task::Threaded` if you need backtraces here."]
  # rubocop:enable Metrics/LineLength
end

#createObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/celluloid/task/fibered.rb', line 6

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

    # Alleged workaround for a MRI memory leak
    # TODO: validate/confirm this is actually necessary
    Fiber.yield if RUBY_ENGINE == "ruby"
  end
end

#deliver(value) ⇒ Object

Resume a suspended task, giving it a value to return if needed



27
28
29
30
31
32
33
# File 'lib/celluloid/task/fibered.rb', line 27

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

#signalObject



22
23
24
# File 'lib/celluloid/task/fibered.rb', line 22

def signal
  Fiber.yield
end

#terminateObject

Terminate this task



36
37
38
39
40
# File 'lib/celluloid/task/fibered.rb', line 36

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