Follow Process Next: The Funnel ProcessUp: Reactive ProcessesPrevious: Out

Follow Process

Follow  outputs the first item of its left input channel, then duplicates its right input on the output.

public class Follow extends ReactiveProcess
{
  private Channel in, left, right, out;
  private boolean first = true;

  public Follow(Channel left,Channel right,Channel out)
  { 
    this.left = left; 
    this.right = right; 
    this.out = out; 
  }

  public Follow(NrpMachine machine,
                    String left,String right,String out)
  { 
    this.left = machine.getChannel(left); 
    this.right = machine.getChannel(right); 
    this.out = machine.getChannel(out); 
    machine.add(this);
  }

 final public String toString(){ 
    return "follow(" + out + "," + left + "," + right + ")";
  }

  protected byte activation(Machine machine)
  {
    Channel in = first ? left : right;
    byte b = fix(in,machine);
    if (b == TERM){
      put(out,in.get(),machine);
      first = false;
      return STOP;
    }
    return b;
  }
}