Class: Signalize::Effect

Inherits:
Object
  • Object
show all
Defined in:
lib/signalize.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(compute) ⇒ Effect

Returns a new instance of Effect.



594
595
596
597
598
599
600
# File 'lib/signalize.rb', line 594

def initialize(compute)
  @_compute = compute
 @_cleanup = nil
  @_sources = nil
  @_next_batched_effect = nil
  @_flags = TRACKING
end

Instance Attribute Details

#_cleanupObject

Returns the value of attribute _cleanup.



592
593
594
# File 'lib/signalize.rb', line 592

def _cleanup
  @_cleanup
end

#_computeObject

Returns the value of attribute _compute.



592
593
594
# File 'lib/signalize.rb', line 592

def _compute
  @_compute
end

#_flagsObject

Returns the value of attribute _flags.



592
593
594
# File 'lib/signalize.rb', line 592

def _flags
  @_flags
end

#_next_batched_effectObject

Returns the value of attribute _next_batched_effect.



592
593
594
# File 'lib/signalize.rb', line 592

def _next_batched_effect
  @_next_batched_effect
end

#_sourcesObject

Returns the value of attribute _sources.



592
593
594
# File 'lib/signalize.rb', line 592

def _sources
  @_sources
end

Instance Method Details

#_callbackObject



602
603
604
605
606
607
608
609
610
611
612
613
614
615
# File 'lib/signalize.rb', line 602

def _callback
  finis = _start

  begin
    compute_executed = false
    @_cleanup = _compute.() if (@_flags & DISPOSED).zero? && @_compute.nil?.!
    compute_executed = true
  ensure
    unless compute_executed
      raise Signalize::Error, "Early return or break detected in effect block"
    end
    finis.(nil) # TODO: figure out this weird shit
  end
end

#_disposeObject



640
641
642
643
644
# File 'lib/signalize.rb', line 640

def _dispose
 @_flags |= DISPOSED

  Signalize.dispose_effect(self) unless (@_flags & RUNNING).nonzero?
end

#_notifyObject



632
633
634
635
636
637
638
# File 'lib/signalize.rb', line 632

def _notify
  unless (@_flags & NOTIFIED).nonzero?
    @_flags |= NOTIFIED
    @_next_batched_effect = Signalize.batched_effect
    Signalize.batched_effect = self
  end
end

#_startObject



617
618
619
620
621
622
623
624
625
626
627
628
629
630
# File 'lib/signalize.rb', line 617

def _start
  Signalize.cycle_detected if (@_flags & RUNNING).nonzero?

  @_flags |= RUNNING
  @_flags &= ~DISPOSED
  Signalize.cleanup_effect(self)
  Signalize.prepare_sources(self)

  Signalize.start_batch
  prev_context = Signalize.eval_context
  Signalize.eval_context = self

  Signalize.method(:end_effect).curry(3).call(self, prev_context) # HUH
end