Class: OpenHAB::RSpec::Mocks::SynchronousExecutor
- Inherits:
-
Object
- Object
- OpenHAB::RSpec::Mocks::SynchronousExecutor
- Defined in:
- lib/openhab/rspec/mocks/synchronous_executor.rb
Instance Attribute Summary collapse
-
#main_thread ⇒ Object
Returns the value of attribute main_thread.
Instance Method Summary collapse
- #execute(runnable) ⇒ Object
-
#initialize ⇒ SynchronousExecutor
constructor
A new instance of SynchronousExecutor.
- #shutdown ⇒ Object
- #shutdown_now ⇒ Object (also: #shutdownNow)
- #submit(runnable) ⇒ Object
Constructor Details
#initialize ⇒ SynchronousExecutor
Returns a new instance of SynchronousExecutor.
23 24 25 26 |
# File 'lib/openhab/rspec/mocks/synchronous_executor.rb', line 23 def initialize # Allocate a (hopefully) big enough pool size to accommodate scheduled tasks super(10) end |
Instance Attribute Details
#main_thread ⇒ Object
Returns the value of attribute main_thread.
21 22 23 |
# File 'lib/openhab/rspec/mocks/synchronous_executor.rb', line 21 def main_thread @main_thread end |
Instance Method Details
#execute(runnable) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/openhab/rspec/mocks/synchronous_executor.rb', line 37 def execute(runnable) if OpenHAB::Core.version < "5.1.0" # @deprecated OH5.1 remove the version guard return super unless Thread.current == main_thread # rubocop:disable Style/SoleNestedConditional end runnable.run end |
#shutdown ⇒ Object
45 |
# File 'lib/openhab/rspec/mocks/synchronous_executor.rb', line 45 def shutdown; end |
#shutdown_now ⇒ Object Also known as: shutdownNow
47 48 49 |
# File 'lib/openhab/rspec/mocks/synchronous_executor.rb', line 47 def shutdown_now [] end |
#submit(runnable) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/openhab/rspec/mocks/synchronous_executor.rb', line 28 def submit(runnable) if OpenHAB::Core.version < "5.1.0" # @deprecated OH5.1 remove the version guard return super unless Thread.current == main_thread # rubocop:disable Style/SoleNestedConditional end value = runnable.respond_to?(:run) ? runnable.run : runnable.call java.util.concurrent.CompletableFuture.completed_future(value) end |