anchor.diff:      Response :: {next_state, client, State}
           | {stop, timeout, State}.
   
  -client(timeout, State=#state{in_process=InProcess}) ->
  -    case InProcess of
  -        {call, From, _} ->
  -            % TODO: Need to send errors responses to all clients
  -            gen_fsm:reply(From, {error, timeout}),
  -            {stop, timeout, State};
  -        _ ->
  -            {next_state, client, State}
  -    end;
  +client(timeout, State=#state{}) ->
  +    error_response(timeout, State);
   client(_Event, State) ->
       {next_state, client, State}.
   
  
positive.code: 
  -record(state, {
      port :: port(),
      queue = queue:new() :: queue(),
      in_process :: {call | switch, From::term(), Timer::term()}
      }).
  
  -opaque instance() :: pid().
  
negative.code:                     {ok, Timer};
                  false ->
                      ok
              end
      catch
          error:badarg ->
              fail
      end.
  
  process_queue(StateName=client, State=#state{queue=Queue}) ->
      case queue:out(Queue) of
          {empty, Queue} ->
              {next_state, StateName, State};
          {{value, Queued}, Queue2} ->
              send_from_queue(Queued, Queue2, StateName, State)
      end;
  process_queue(StateName=server, State=#state{port=Port, queue=Queue}) ->
      case queue:out(Queue) of
          {empty, Queue} ->
              {next_state, StateName, State#state{in_process=undefined}};
          {{value, {response, Data}}, Queue2} ->
              case send_data(Port, Data, false) of
                  ok ->
                      {next_state, StateName, State#state{queue=Queue2}};
                  fail ->
                      {stop, port_closed, State}
              end
      end.
  
  send_request(Queued={Type, From, Data}, StateName, State=#state{port=Port,
          queue=Queue, in_process=InProcess}) ->
      case InProcess of
          undefined ->
              case send_data(Port, Data) of
                  {ok, Timer} ->
                      Info = {Type, From, Timer},
                      {next_state, StateName, State#state{in_process=Info}};
                  fail ->
                      {stop, port_closed, State}
              end;
          _ ->
              Queue2 = queue:in(Queued, Queue),
              {next_state, StateName, State#state{queue=Queue2}}
      end.
  
  send_from_queue({Type, From, Data}, Queue, StateName,
          State=#state{port=Port}) ->
      case send_data(Port, Data) of
          {ok, Timer} ->
              Info = {Type, From, Timer},
              {next_state, StateName, State#state{in_process=Info, queue=Queue}};
          fail ->
              {stop, port_closed, State}
      end.
  
  handle_response(ExpectedType, Response, State=#state{in_process=InProcess},
          StateName) ->
      case InProcess of
          {ExpectedType, From, Timer} ->
              gen_fsm:cancel_timer(Timer),
              gen_fsm:reply(From, Response),
              process_queue(StateName, State#state{in_process=undefined});
          undefined ->
              {stop, orphan_response, State};
          _ ->
              {stop, unexpected_response, State}
      end.
  
  error_response(Error, State=#state{in_process=InProcess}) ->
      case InProcess of
          {_Type, From, _Timer} ->
              gen_fsm:reply(From, {error, Error});
          undefined ->
              ok
      end,
      {stop, Error, State}.
  