Class: Contender::Pool::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/contender/pool/task.rb

Overview

Encapsulates a task that is either waiting for execution or has been executed

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block, arguments) ⇒ undefined

Parameters:

  • block (Proc)
  • arguments (Array)


17
18
19
20
21
# File 'lib/contender/pool/task.rb', line 17

def initialize(block, arguments)
  @block = block
  @arguments = arguments
  @executed = false
end

Instance Attribute Details

#argumentsArray (readonly)

Returns The arguments that the block will be executed with.

Returns:

  • (Array)

    The arguments that the block will be executed with



6
7
8
# File 'lib/contender/pool/task.rb', line 6

def arguments
  @arguments
end

#blockProc (readonly)

Returns The block that will be executed by a pool worker.

Returns:

  • (Proc)

    The block that will be executed by a pool worker



9
10
11
# File 'lib/contender/pool/task.rb', line 9

def block
  @block
end

#exceptionException (readonly)

Returns Exception that occured during task execution.

Returns:

  • (Exception)

    Exception that occured during task execution



12
13
14
# File 'lib/contender/pool/task.rb', line 12

def exception
  @exception
end

Instance Method Details

#executeundefined

Executes the block with the provided arguments

Returns:

  • (undefined)


41
42
43
44
45
46
47
48
49
# File 'lib/contender/pool/task.rb', line 41

def execute
  begin
    @block.call *@arguments
  rescue Exception => exception
    @exception = exception
  end

  @executed = true
end

#executed?Boolean

Returns true if this task has been executed

Returns:

  • (Boolean)


27
28
29
# File 'lib/contender/pool/task.rb', line 27

def executed?
  @executed
end

#failed?Boolean

Returns true if the execution of this task resulted in an exception

Returns:

  • (Boolean)


35
36
37
# File 'lib/contender/pool/task.rb', line 35

def failed?
  !!@exception
end