Class: Dataflow::Variable
Overview
Note that this class uses instance variables directly rather than nicely initialized instance variables in get/set methods for memory and performance reasons
Constant Summary collapse
- LOCK =
Monitor.new
Instance Method Summary collapse
- #__activate_trigger__ ⇒ Object
-
#__binding_condition__ ⇒ Object
Lazy-load conditions to be nice on memory usage.
- #__dataflow__? ⇒ Boolean
- #__unify__(value) ⇒ Object
- #__wait__ ⇒ Object
-
#initialize(&block) ⇒ Variable
constructor
A new instance of Variable.
- #method_missing(name, *args, &block) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Variable
Returns a new instance of Variable.
69 |
# File 'lib/vendor/dataflow/dataflow.rb', line 69 def initialize(&block) @__trigger__ = block if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
108 109 110 111 112 |
# File 'lib/vendor/dataflow/dataflow.rb', line 108 def method_missing(name, *args, &block) return "#<Dataflow::Variable:#{__id__} unbound>" if !@__bound__ && name == :inspect __wait__ @__value__.__send__(name, *args, &block) end |
Instance Method Details
#__activate_trigger__ ⇒ Object
90 91 92 93 94 |
# File 'lib/vendor/dataflow/dataflow.rb', line 90 def __activate_trigger__ @__value__ = @__trigger__.call @__bound__ = true @__trigger__ = nil # GC end |
#__binding_condition__ ⇒ Object
Lazy-load conditions to be nice on memory usage
72 |
# File 'lib/vendor/dataflow/dataflow.rb', line 72 def __binding_condition__() @__binding_condition__ ||= LOCK.new_cond end |
#__dataflow__? ⇒ Boolean
114 115 116 |
# File 'lib/vendor/dataflow/dataflow.rb', line 114 def __dataflow__? true end |
#__unify__(value) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/vendor/dataflow/dataflow.rb', line 74 def __unify__(value) LOCK.synchronize do __activate_trigger__ if @__trigger__ if @__bound__ return @__value__.__unify__(value) if @__value__.__dataflow__? rescue nil raise UnificationError, "#{@__value__.inspect} != #{value.inspect}" if self != value else @__value__ = value @__bound__ = true __binding_condition__.broadcast # wakeup all method callers @__binding_condition__ = nil # GC end end @__value__ end |