Class: Dataflow::Port

Inherits:
Object show all
Includes:
Dataflow
Defined in:
lib/vendor/dataflow/dataflow/port.rb

Defined Under Namespace

Classes: Stream

Constant Summary collapse

LOCK =
Mutex.new

Constants included from Dataflow

UnificationError, VERSION

Instance Method Summary collapse

Methods included from Dataflow

#barrier, #by_need, #flow, included, #local, #need_later, #unify

Constructor Details

#initialize(x) ⇒ Port

Create a stream object, bind it to the input variable Instance variables are necessary because @end is state



39
40
41
42
# File 'lib/vendor/dataflow/dataflow/port.rb', line 39

def initialize(x)
  @end = Stream.new
  unify x, @end
end

Instance Method Details

#send(value) ⇒ Object

This needs to be synchronized because it uses @end as state



45
46
47
48
49
50
51
# File 'lib/vendor/dataflow/dataflow/port.rb', line 45

def send value
  LOCK.synchronize do
    unify @end.head, value
    unify @end.tail, Stream.new
    @end = @end.tail
  end
end