Class: PromisePool::Task

Inherits:
Struct
  • Object
show all
Defined in:
lib/promise_pool/task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cancelledObject

Returns the value of attribute cancelled

Returns:

  • (Object)

    the current value of cancelled



3
4
5
# File 'lib/promise_pool/task.rb', line 3

def cancelled
  @cancelled
end

#jobObject

Returns the value of attribute job

Returns:

  • (Object)

    the current value of job



3
4
5
# File 'lib/promise_pool/task.rb', line 3

def job
  @job
end

#mutexObject

Returns the value of attribute mutex

Returns:

  • (Object)

    the current value of mutex



3
4
5
# File 'lib/promise_pool/task.rb', line 3

def mutex
  @mutex
end

#threadObject

Returns the value of attribute thread

Returns:

  • (Object)

    the current value of thread



3
4
5
# File 'lib/promise_pool/task.rb', line 3

def thread
  @thread
end

Instance Method Details

#call(working_thread) ⇒ Object

this should never fail



5
6
7
8
9
10
11
12
# File 'lib/promise_pool/task.rb', line 5

def call working_thread
  mutex.synchronize do
    return if cancelled
    self.thread = working_thread
  end
  job.call
  true
end

#cancelObject



14
15
16
# File 'lib/promise_pool/task.rb', line 14

def cancel
  self.cancelled = true
end