Class: Rclrb::Executor
- Inherits:
-
Object
- Object
- Rclrb::Executor
- Defined in:
- lib/rclrb/executor.rb
Overview
An executor controls the threading model used to process callbacks. Callbacks are units of work like subscription callbacks, timer callbacks, and service calls. An executor controls which threads callbacks get executed in.
Instance Method Summary collapse
-
#add_node(node) ⇒ Object
Add a node to the executor.
-
#initialize(*nodes) ⇒ Executor
constructor
A new instance of Executor.
- #shutdown(exitcode) ⇒ Object
-
#spin ⇒ Object
Spin continuously untill shutdown was requested.
Constructor Details
#initialize(*nodes) ⇒ Executor
Returns a new instance of Executor.
7 8 9 10 11 12 |
# File 'lib/rclrb/executor.rb', line 7 def initialize(*nodes) @nodes = nodes @groups = nodes.map { |x| x.default_callback_group } @running = true @exitcode = 0 end |
Instance Method Details
#add_node(node) ⇒ Object
Add a node to the executor
15 16 17 18 |
# File 'lib/rclrb/executor.rb', line 15 def add_node(node) @nodes.append node @groups.append node.default_callback_group end |
#shutdown(exitcode) ⇒ Object
19 20 21 22 23 |
# File 'lib/rclrb/executor.rb', line 19 def shutdown(exitcode) @exitcode = exitcode @running = false Rclrb.rcl_signal_guard_condition.trigger end |
#spin ⇒ Object
Spin continuously untill shutdown was requested
26 27 28 29 30 31 32 33 34 |
# File 'lib/rclrb/executor.rb', line 26 def spin() while @running and not Rclrb.rcl_shutdown_requested? wait_set = WaitSet.new threads = @groups.map { |g| g.spin wait_set } threads.each { |t| t.join } wait_set.wait end return @exitcode end |