Class: Applitools::Future

Inherits:
Object
  • Object
show all
Defined in:
lib/applitools/core/future.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(semaphore, &block) ⇒ Future

Returns a new instance of Future.

Raises:

  • (Applitools::EyesIllegalArgument)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/applitools/core/future.rb', line 5

def initialize(semaphore, &block)
  raise Applitools::EyesIllegalArgument, 'Applitools::Future must be initialized with a block' unless block_given?
  self.block = block
  self.semaphore = semaphore
  self.thread = Thread.new do
    begin
      self.result = block.call(semaphore)
    rescue StandardError => e
      Applitools::EyesLogger.logger.error "Failed to execute future"
      Applitools::EyesLogger.logger.error e.message
      Applitools::EyesLogger.logger.error e.backtrace.join( ' ')
    end
  end
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



3
4
5
# File 'lib/applitools/core/future.rb', line 3

def block
  @block
end

#resultObject

Returns the value of attribute result.



3
4
5
# File 'lib/applitools/core/future.rb', line 3

def result
  @result
end

#semaphoreObject

Returns the value of attribute semaphore.



3
4
5
# File 'lib/applitools/core/future.rb', line 3

def semaphore
  @semaphore
end

#threadObject

Returns the value of attribute thread.



3
4
5
# File 'lib/applitools/core/future.rb', line 3

def thread
  @thread
end

Instance Method Details

#getObject



20
21
22
23
# File 'lib/applitools/core/future.rb', line 20

def get
  thread.join(15)
  result
end