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



36
37
38
39
40
# File 'lib/openhab/rspec/mocks/synchronous_executor.rb', line 36

def execute(runnable)
  return super unless Thread.current == main_thread

  runnable.run
end

#shutdownObject



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

def shutdown; end

#shutdown_nowObject Also known as: shutdownNow



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

def shutdown_now
  []
end

#submit(runnable) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/openhab/rspec/mocks/synchronous_executor.rb', line 28

def submit(runnable)
  return super unless Thread.current == main_thread

  runnable.respond_to?(:run) ? runnable.run : runnable.call

  java.util.concurrent.CompletableFuture.completed_future(nil)
end