Class: OpenHAB::RSpec::Mocks::SynchronousExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/openhab/rspec/mocks/synchronous_executor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSynchronousExecutor

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_threadObject

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

#shutdownObject



45
# File 'lib/openhab/rspec/mocks/synchronous_executor.rb', line 45

def shutdown; end

#shutdown_nowObject 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