Class: Celluloid::Task::Fibered
- Inherits:
-
Celluloid::Task
- Object
- Celluloid::Task
- Celluloid::Task::Fibered
- Defined in:
- lib/celluloid/task/fibered.rb
Overview
Tasks with a Fiber backend
Defined Under Namespace
Classes: StackError
Constant Summary
Constants inherited from Celluloid::Task
Instance Attribute Summary
Attributes inherited from Celluloid::Task
#chain_id, #guard_warnings, #meta, #status, #type
Instance Method Summary collapse
- #backtrace ⇒ Object
- #create ⇒ Object
-
#deliver(value) ⇒ Object
Resume a suspended task, giving it a value to return if needed.
- #signal ⇒ Object
-
#terminate ⇒ Object
Terminate this task.
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
#backtrace ⇒ Object
40 41 42 |
# File 'lib/celluloid/task/fibered.rb', line 40 def backtrace ["#{self.class} backtrace unavailable. Please try `Celluloid.task_class = Celluloid::Task::Threaded` if you need backtraces here."] end |
#create ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# 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 # TODO: Determine why infinite thread leakage happens under jRuby, if `Fiber.yield` is used: Fiber.yield unless RUBY_PLATFORM == "java" end end |
#deliver(value) ⇒ Object
Resume a suspended task, giving it a value to return if needed
25 26 27 28 29 30 31 |
# File 'lib/celluloid/task/fibered.rb', line 25 def deliver(value) @fiber.resume value rescue SystemStackError => ex raise StackError, "#{ex} @#{[: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 |
#signal ⇒ Object
20 21 22 |
# File 'lib/celluloid/task/fibered.rb', line 20 def signal Fiber.yield end |
#terminate ⇒ Object
Terminate this task
34 35 36 37 38 |
# File 'lib/celluloid/task/fibered.rb', line 34 def terminate super rescue FiberError # If we're getting this the task should already be dead end |