Module: Dataflow
Defined Under Namespace
Classes: Actor, FutureQueue, Port, Variable
Constant Summary
collapse
- VERSION =
"0.3.1"
- UnificationError =
Class.new StandardError
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Class Attribute Details
Returns the value of attribute forker.
6
7
8
|
# File 'lib/vendor/dataflow/dataflow.rb', line 6
def forker
@forker
end
|
Class Method Details
.included(cls) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/vendor/dataflow/dataflow.rb', line 10
def self.included(cls)
class << cls
def declare(*readers)
readers.each do |name|
class_eval <<-RUBY
def #{name}
return @__dataflow_#{name}__ if defined? @__dataflow_#{name}__
Variable::LOCK.synchronize { @__dataflow_#{name}__ ||= Variable.new }
end
RUBY
end
end
end
end
|
Instance Method Details
#barrier(*variables) ⇒ Object
39
40
41
|
# File 'lib/vendor/dataflow/dataflow.rb', line 39
def barrier(*variables)
variables.each{|v| v.__wait__ }
end
|
#by_need(&block) ⇒ Object
35
36
37
|
# File 'lib/vendor/dataflow/dataflow.rb', line 35
def by_need(&block)
Variable.new &block
end
|
#flow(output = nil, &block) ⇒ Object
43
44
45
46
47
48
|
# File 'lib/vendor/dataflow/dataflow.rb', line 43
def flow(output=nil, &block)
Dataflow.forker.call do
result = block.call
unify output, result if output
end
end
|
#local(&block) ⇒ Object
25
26
27
28
29
|
# File 'lib/vendor/dataflow/dataflow.rb', line 25
def local(&block)
return Variable.new unless block_given?
vars = Array.new(block.arity) { Variable.new }
block.call *vars
end
|
#need_later(&block) ⇒ Object
50
51
52
53
54
55
|
# File 'lib/vendor/dataflow/dataflow.rb', line 50
def need_later(&block)
local do |future|
flow(future) { block.call }
future
end
end
|
#unify(variable, value) ⇒ Object
31
32
33
|
# File 'lib/vendor/dataflow/dataflow.rb', line 31
def unify(variable, value)
variable.__unify__ value
end
|