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.
65 |
# File 'lib/vendor/dataflow/dataflow.rb', line 65 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
104 105 106 107 108 |
# File 'lib/vendor/dataflow/dataflow.rb', line 104 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
86 87 88 89 90 |
# File 'lib/vendor/dataflow/dataflow.rb', line 86 def __activate_trigger__ @__value__ = @__trigger__.call @__bound__ = true @__trigger__ = nil # GC end |
#__binding_condition__ ⇒ Object
Lazy-load conditions to be nice on memory usage
68 |
# File 'lib/vendor/dataflow/dataflow.rb', line 68 def __binding_condition__() @__binding_condition__ ||= LOCK.new_cond end |
#__dataflow__? ⇒ Boolean
110 111 112 |
# File 'lib/vendor/dataflow/dataflow.rb', line 110 def __dataflow__? true end |
#__unify__(value) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/vendor/dataflow/dataflow.rb', line 70 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 |