Class: Procrastinate::Task::Callable

Inherits:
Object
  • Object
show all
Defined in:
lib/procrastinate/task/callable.rb

Overview

A task that calls the block and returns the result of execution.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block) ⇒ Callable

Returns a new instance of Callable.



11
12
13
14
# File 'lib/procrastinate/task/callable.rb', line 11

def initialize(block)
  @b = block
  @result = Result.new
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



8
9
10
# File 'lib/procrastinate/task/callable.rb', line 8

def block
  @block
end

#resultObject (readonly)

Returns the value of attribute result.



9
10
11
# File 'lib/procrastinate/task/callable.rb', line 9

def result
  @result
end

Instance Method Details

#run(endpoint) ⇒ Object

Runs this task. Gets passed an endpoint that can be used to communicate values back to the master. Every time you write a value to that endpoint (using #send), the server will call #incoming_message on the task object in the master process. This allows return values and other communication from children to the master (and to the caller in this case).



22
23
24
25
# File 'lib/procrastinate/task/callable.rb', line 22

def run(endpoint)
  r = @b.call
  endpoint.call(r) if endpoint
end