anchor.diff:                  }).
   
   -record(state,{ id,
  -                state,
  -                word
  +                state
                 }).
    
   % API
  
positive.code: % INTERNAL
  
  loop(State) ->
     ID   = State#state.id,
     Word = State#state.word,
  
     receive
        { close,PID } ->
           PID ! { closed,{channel,ID} },
           closed;
  
        { write,Value,PID } ->
           case State#state.state of 
              { read_wait,READER } ->
                 READER ! { read,   {channel,ID},Value },
                 PID    ! { written,{channel,ID}       },
                 loop(State#state{ state = idle,
                                   word  = undefined });
                 
              _else ->
                 PID ! { written,{channel,ID} },
                 loop(State#state{ word=Value })
              end;
  
  
        {read,PID } ->
           case Word of
              undefined -> 
                 loop(State#state{ state={read_wait,PID} 
                                 });
  
              _else -> 
                 PID ! { read,{channel,ID},Word },
                 loop(State)
              end;
  
  
negative.code: 
  write_then_read_test() ->
     Channel = create(666),
     M       = self(),
     spawn(fun() ->                   M ! { write,write(Channel,123) } end),
     spawn(fun() -> timer:sleep(500), M ! { read, read (Channel)     } end),
     ?assertEqual({ok,{ok,123}},wait(undefined,undefined)),
     ?assertEqual(closed,close(Channel)).
  
  read_then_write_test() ->
     Channel = create(666),
     M       = self(),
     spawn(fun() ->                   M ! { read, read (Channel)     } end),
     spawn(fun() -> timer:sleep(500), M ! { write,write(Channel,123) } end),
     ?assertEqual({ok,{ok,123}},wait(undefined,undefined)),
     ?assertEqual(closed,close(Channel)).
   
  wait({write,W},{read,R}) ->
     {W,R};
  