Class: Observed::ProcTask
Instance Attribute Summary
Attributes inherited from Task
Instance Method Summary collapse
-
#initialize(args, &block) ⇒ ProcTask
constructor
A new instance of ProcTask.
- #now(data = {}, options = nil) ⇒ Object
Methods inherited from Task
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={}, =nil) @executor.submit { result = @block.call(data, ) yield result if block_given? notify_listener(data: data, options: , result: result) } end |