Class: Observed::ProcTask

Inherits:
Task
  • Object
show all
Defined in:
lib/observed/task.rb

Instance Attribute Summary

Attributes inherited from Task

#name

Instance Method Summary collapse

Methods inherited from Task

#compose, #then

Constructor Details

#initialize(args, &block) ⇒ ProcTask

Returns a new instance of ProcTask.



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/observed/task.rb', line 82

def initialize(args, &block)
  @executor = args[:executor] || fail('Missing a value for :executor')
  @listener = args[:listener] || fail('Missing a value for :listener')
  @logger = args[:logger]
  @block = block
  @next_task = NoOpTask.instance

  if @logger.nil?
    @logger = ::Logger.new(STDERR)
    @logger.level = ::Logger::WARN
  end
end

Instance Method Details

#now(data = {}, options = nil) ⇒ Object



94
95
96
97
98
99
100
# File 'lib/observed/task.rb', line 94

def now(data={}, options=nil)
  @executor.submit {
    result = @block.call(data, options)
    yield result if block_given?
    notify_listener(data: data, options: options, result: result)
  }
end