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)


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

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 = 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

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

#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



22
23
24
25
# File 'lib/applitools/core/future.rb', line 22

def get
  thread.join(15)
  result
end