Class: MotionWiretap::WiretapProc

Inherits:
WiretapTarget show all
Defined in:
lib/motion-wiretap/all/wiretap.rb

Instance Attribute Summary

Attributes inherited from WiretapTarget

#target

Attributes inherited from Wiretap

#value

Instance Method Summary collapse

Methods inherited from Wiretap

#and_then, #cancel!, #combine, #dealloc, #enqueue, #filter, #listen, #map, #on_error, #queue, #reduce, #teardown, #trigger_changed, #trigger_changed_on, #trigger_completed, #trigger_completed_on, #trigger_error, #trigger_error_on

Constructor Details

#initialize(target, queue, and_then) ⇒ WiretapProc

Returns a new instance of WiretapProc.



415
416
417
418
419
420
421
422
# File 'lib/motion-wiretap/all/wiretap.rb', line 415

def initialize(target, queue, and_then)
  @started = false
  super(target)
  and_then(&and_then) if and_then
  queue(queue) if queue

  start if and_then
end

Instance Method Details

#startObject



424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
# File 'lib/motion-wiretap/all/wiretap.rb', line 424

def start
  unless @started
    @started = true
    enqueue do
      begin
        if @target.arity == 0
          @target.call
        else
          @target.call(-> (value) { self.trigger_changed(value) })
        end
      rescue Exception => error
        trigger_error(error)
      else
        trigger_completed
      end
    end
  end
end