Class: Applitools::Future

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

Constant Summary collapse

DEFAULT_TIMEOUT =
350

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(semaphore, description = nil, &block) ⇒ Future

Returns a new instance of Future.

Raises:

  • (Applitools::EyesIllegalArgument)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/applitools/core/future.rb', line 12

def initialize(semaphore, description = nil, &block)
  raise Applitools::EyesIllegalArgument, 'Applitools::Future must be initialized with a block' unless block_given?
  self.block = block
  self.semaphore = semaphore
  self.description = description
  self.thread = Thread.new do
    begin
      self.result = yield(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

Class Attribute Details

.timeoutObject

Returns the value of attribute timeout.



8
9
10
# File 'lib/applitools/core/future.rb', line 8

def timeout
  @timeout
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



5
6
7
# File 'lib/applitools/core/future.rb', line 5

def block
  @block
end

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/applitools/core/future.rb', line 5

def description
  @description
end

#resultObject

Returns the value of attribute result.



5
6
7
# File 'lib/applitools/core/future.rb', line 5

def result
  @result
end

#semaphoreObject

Returns the value of attribute semaphore.



5
6
7
# File 'lib/applitools/core/future.rb', line 5

def semaphore
  @semaphore
end

#threadObject

Returns the value of attribute thread.



5
6
7
# File 'lib/applitools/core/future.rb', line 5

def thread
  @thread
end

Instance Method Details

#getObject

Raises:

  • (Applitools::EyesError)


28
29
30
31
32
# File 'lib/applitools/core/future.rb', line 28

def get
  thread.join(self.class.timeout)
  raise Applitools::EyesError, "Failed to execute future - got nil result! (#{description})" if result.nil?
  result
end